Xbase++
Xbase++
Xml TagPath Property Explained
See more XML Examples
Demonstrates and explains the TagPath property.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oXml
LOCAL nFound
LOCAL cTagPath
nSuccess := 0
oXml := CreateObject("Chilkat.Xml")
// Load some XML:
nSuccess := oXml:LoadXml("<a><bbb><ccc><ddd>1</ddd><ddd><z>zzz</z></ddd><ddd>3</ddd></ccc></bbb></a>")
? oXml:GetXml()
// This is what we have:
// <?xml version="1.0" encoding="utf-8"?>
// <a>
// <bbb>
// <ccc>
// <ddd>1</ddd>
// <ddd>
// <z>zzz</z>
// </ddd>
// <ddd>3</ddd>
// </ccc>
// </bbb>
// </a>
// The TagPath property is read-only property that returns the unique path to the
// node from the document root.
// For example:
nFound := oXml:SearchForTag2(oXml, "z")
IF (nFound == 1)
// We found a node having the tag "z".
// The TagPath property tells us the location in the document.
cTagPath := oXml:TagPath
? cTagPath
// The tagPath is bbb|ccc|ddd[1]|z
// If we to back to the document root, we can get to the given node via the tagPath.
oXml:GetRoot2()
? oXml:Tag
// The root tag is "a".
// Follow the tagPath to the "z" node:
nFound := oXml:FindChild2(cTagPath)
? "found = " + Str(nFound) + ", tag = " + oXml:Tag
// We are now at "z".
ENDIF
oXml:destroy()