0

Myxml file is like this

<DATAPACKET>
          <ROWDATA>
             <LINE1>
               <ROW Attr1="111" Attr2="2121" />
             </LINE1>
             <LINE2>
               <ROW At1="11" At2="2211" />
             </LINE2>
           </ROWDATA>
          <ROWDATA>
             <LINE1>
               <ROW Attr1="333" Attr2="2121" />
             </LINE1>
             <LINE2>
               <ROW At1="11" At2="2211" />
             </LINE2>
           </ROWDATA>
....
</DATAPACKET>

and my code to parse it
i use delphi7 and TXMLDocument

Rows := MyXml.DocumentElement.ChildNodes.First ;//Get first rowdata
Line1 := Rows.ChildNodes.First ;    // then first line1
Curnode := Line1.ChildNodes.First ;  // 
For kk := 0 To Rows.ChildNodes.Count-1 Do Begin
    if (Curnode.Attributes['Attr1'] <> null) then
         Form1.Memo1.Lines.Add(CurNode.Attributes['Attr1']) ;
    Curnode := Rows.NextSibling;
End ;

it just reads 111 but can't 333 and ...

best regards

  • 1
    Of course it can't. The first `ROW` element has no siblings. Its *parent* (`LINE1`) has a sibling (`LINE2`), but siblings are not the same as cousins. Furthermore, `Curnode` starts out referring to a `ROW` element, but at the end of the first iteration of the loop, you assign it the next `ROWDATA` element, which has no `Attr1` attributes at all. – Rob Kennedy May 24 '13 at 14:20
  • So how will i get next row. i think my problem is on iterating rows. – user2417750 May 24 '13 at 14:48
  • You might try using the *XPath* query `//ROW`, and then iterate over that list. It gives you a list of all the `ROW` elements in the entire document, irrespective of their parents. If you don't want to do that, then consider that you have a *tree*, and you want to iterate over its *leaves*. Algorithms for *tree traversals* apply equally well to XML, which is a tree-like data structure. I've just given you lots of new vocabulary words; make sure to do some reading about them before your next follow-up question. – Rob Kennedy May 24 '13 at 14:56
  • You might find [Libraries and tutorials for XML in Delphi](http://stackoverflow.com/q/263419/62576) useful. – Ken White May 24 '13 at 16:29
  • NativeXml solves my problem. Can read without a problem.http://www.simdesign.nl/xml.html – user2417750 May 27 '13 at 10:36

0 Answers0