<?xml version="1.0" encoding="utf-8"?> <Data> <String1>Test1</String1> <String2>Test2</String2> <DataChild> <String3>Test10</String3> <String4>Test20</String4> </DataChild> <DataChild> <String3>Test30</String3> <String4>Test40</String4> </DataChild> </Data>
Doc DotNet System.Xml.XmlDocument.'System.Xml ParrentNode DotNet System.Xml.XmlNode.'System.Xml ChildNode DotNet System.Xml.XmlNode.'System.Xml NodeList DotNet System.Xml.XmlNodeList.'System.Xml ChildNodeList DotNet System.Xml.XmlNodeList.'System.Xml i Integer j Integer
Doc := Doc.XmlDocument(); Doc.Load('V:\NAV\XMLExample\MibusoXML.xml'); ParrentNode := Doc.SelectSingleNode('Data'); NodeList := ParrentNode.ChildNodes(); // NodeList ... String1, String2, DataChild, DataChild FOR i := 0 TO NodeList.Count -1 DO BEGIN ChildNode := NodeList.ItemOf(i); CASE ChildNode.Name OF 'DataChild': BEGIN ChildNodeList := ChildNode.ChildNodes(); FOR j := 0 TO ChildNodeList.Count - 1 DO BEGIN ChildNode := ChildNodeList.ItemOf(j); MESSAGE('I''''m a DataChild Node Name: %1 InnerText: %2',ChildNode.Name,ChildNode.InnerText); END; END; ELSE BEGIN MESSAGE('I''''m a Data Node Name: %1 InnerText: %2',ChildNode.Name,ChildNode.InnerText); END; END; END;
Answers
this is a really quick and dirty example how you can read you XML.
XML:
Variables:
If you invest more time in this you will see that you can create a code which is much more flexible or maybe also recursive. There are a lot examples in c# which you can convert to c/al.
thinknavblog.wordpress.com