In an XML document with prolog, how can I get the children of the root node with their attributes?

412 views Asked by At

I have this XML file:

<?xml version="1.0" encoding="UTF-8"?>
<MyApp_Favorites version="1.0">
  <Favorite Path="D:\MyTextA.txt" Page="2"/>
  <Favorite Path="D:\MyTextB.txt" Page="33"/>
  <Favorite Path="D:\MyTextC.txt" Page="1"/>
</MyApp_Favorites>

Now I try to start to read the children of MyApp_Favorites and their respective attributes by starting to read the root node (and then I would try to read the children of the root node):

procedure TFormMain.LoadFavorites;
var
  XMLDoc: TXMLDocument;
  ThisRootNode, ThisFavNode: IXMLNode;
begin
  XMLDoc := TXMLDocument.Create(nil);
  XMLDoc.LoadFromFile('R:\test.xml');
  XMLDoc.Active := True;
  ThisRootNode := XMLDoc.ChildNodes.First;
  CodeSite.Send('ThisRootNode.Text', ThisRootNode.Text);

However, ThisRootNode.Text gives me back:

version="1.0" encoding="UTF-8"

But doesn't the XML specification say that the XML Prolog is not part of the XML document content? So why do I get the XML Prolog as part of the XML document? And how can I get the root node MyApp_Favorites and then its Favorite child nodes with their attributes?

0

There are 0 answers