0

This is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<UsersF Ver="1.1">
    <row User="1" Pin="2y44ic" ExtPag="full"/>
    <row User="2" pin="tfde88" ExtPag="e45" />
    <row User="3" Pin="9gr444466gg" Level="nov" GamePag="3" />
</UsersF>

And this is the code that I get access and put a string-grid... I use the nextgrid ...

procedure showXmlToString;
Count:= 0;
Conf.nxtgrd.AddRow(71);
Conf.nxtgrd.BeginUpdate;
with FXml.Root do
for i := 0 to NodeCount - 1 do
  begin
    if Nodes[i].Name <> 'Ver' then
      begin
        Conf.nxtgrd.Cell[0,count].AsString := Nodes[i].Nodes[1].Value;
        Conf.nxtgrd.Cell[1,count].AsString := Nodes[i].Nodes[2].Value;
        Conf.nxtgrd.Cell[2,count].AsString := Nodes[i].Nodes[3].Value;            
        Conf.nxtgrd.Cell[3,count].AsString := Nodes[i].Nodes[4].Value;
       count := count + 1;
      end;
  end;

When it come to line that the node not exits I get the error.

rekire
  • 47,260
  • 30
  • 167
  • 264
azrael11
  • 417
  • 6
  • 18

1 Answers1

0

To accessing the attributes you can use TXmlNode.AttributeCount to iterate numbers of attributes available. If the main point of this code is to obtain the attributes, you can access them using TXmlNode.Containers.

Let say you want to get all the attributes name & value, you can using following iteration:

with FXML.Root do
for i := 0 to ContainerCount - 1 do
begin
  Log(Format('ContainersName=%s AtribNumber=%d',[Containers[i].Name,i]));
  for j:=0 to Containers[i].AttributeCount-1 do begin
    Log(Format('AttribName=%s AttribVal=%s',[Containers[i].Attributes[j].Name,Containers[i].Attributes[j].Value]));
  end;
end;

In this example Log procedure will display the string to the screen. As the result the output will be like this:

ContainersName=row AtribNumber=0
AttribName=User AttribVal=1
AttribName=Pin AttribVal=2y44ic
AttribName=ExtPag AttribVal=full
ContainersName=row AtribNumber=1
AttribName=User AttribVal=2
AttribName=pin AttribVal=tfde88
AttribName=ExtPag AttribVal=e45
ContainersName=row AtribNumber=2
AttribName=User AttribVal=3
AttribName=Pin AttribVal=9gr444466gg
AttribName=Level AttribVal=nov
AttribName=GamePag AttribVal=3

I hope this help you.

sybond
  • 167
  • 9
  • oooh.. do you mean checking the Attributes (User,Pin,Level..), you can use `TXmlNode.AttributeCount` to iterate and retrieves the attributes value using `TXmlNode.AttributeValue`. – sybond Oct 08 '12 at 01:46
  • yes i mean the attributes... the txmlnode.attributecount is wrong bcs some times gives me the same number but dont tell me which node is missing... – azrael11 Oct 08 '12 at 05:15
  • This is work sybond but really is a bit confusion if you want to find a simple subnote is exist... i think the native xml have something like that... if getvaluebynodename('pin') <> '' then exist... Thanks by the way... – azrael11 Oct 10 '12 at 20:47