Parse XML data

I have a XML file with this structure:

</object>
<object type="PRODUCT" id="z113">
    <attribute name="uuid" type="string">7F57C42A-BD6E-4362-9291-F5C5FEC6A875</attribute>
    <attribute name="title" type="string">My Application</attribute>
    <attribute name="registeredname" type="string">Peter @pps4Me</attribute>
    <attribute name="registeredemail" type="string">info@myurl.com</attribute>
    <attribute name="purchaseprice" type="decimal">29.95</attribute>
    <attribute name="purchaseordernumber" type="string">53720AD543</attribute>
    <attribute name="purchasedate" type="date">187913763.00000000000000000000</attribute>
    <attribute name="purchasecurrency" type="string">€</attribute>
    <attribute name="productversion" type="string"></attribute>
    <relationship name="appicon" type="1/1" destination="ICON" idrefs="z619"></relationship>
    <relationship name="attachedfiles" type="0/0" destination="ATTACHEDFILE" idrefs="z284"></relationship>
</object>

sub ReadXML()
Var swNode As XmlNode
Var uwNode As XmlNode
Var xName as XmlNode
var xmName as string
var xmID as string
var xmType as string
var xmIDRefs as string
var xmDestination as string

For y As Integer = 0 To swNode.ChildCount - 1
uwNode = swNode.Child(y)
xmName = uwNode.GetAttribute(“name”)
xmID = swNode.GetAttribute(“id”)
xmType = swNode.GetAttribute(“type”)
xmIDRefs = uwNode.GetAttribute(“idrefs”)
xmDestination = uwNode.GetAttribute(“destination”)
xmDate = uwNode.GetAttribute(“date”)

textArea1.AddText(xmName+ chr(9))
textArea1.AddText(xmID + chr(9))
textArea1.AddText(xmType + chr(9))
TextArea1.AddText(xmIDRefs + chr(9))
TextArea1.AddText(xmDate + chr(9))
textArea1.AddText(xmDestination + EndOfLine)

For x As Integer = 0 To swNode.ChildCount - 1
xName = swNode.Child(x)
textArea1.AddText(“xName” + x.ToText + “=” + xName.GetAttribute(“name”) + EndOfLine + _
“RegName” + x.ToText + “=” + xName.GetAttribute(“date”)) + EndOfLine
Next

textArea1.AddText(EndOfLine)

Next

END SUB

The outout is this:
registeredemail z518 PRODUCT
xName0=uuid
RegName0=
xName1=title
RegName1=
xName2=serialnumber
RegName2=
xName3=registeredname
RegName3=
xName4=registeredemail
RegName4=
xName5=registeredcompany
RegName5=
xName6=purchasedate
RegName6=
xName7=purchasecurrency
RegName7=
xName8=productwebsite
RegName8=
xName9=productversion
RegName9=
xName10=appicon
RegName10=
xName11=attachedfiles
RegName11=

So, I got the names of the fields (serialnumber, registeredname, etc), but not the values. Ho can I get the values?

uwNode = swNode.Child(y) fieldValue = uwNode.Child(0).value

Another question: How can I get the value of these items:


There are no values in those nodes. Right? Just attributes.

“ICON” idrefs is a reference to another item (ICON) in this XML and “ATTACHEDFILE” idrefs=“z284” is a relation to an item for the attachments. So I would get the values from “idrefs” for ICONS and ATTCHEDFLIE.

In that case, you need to do an XQL query to find the nodes referred to by the attributes. I can’t tell you too much about that as I only use the most simplest cases of XQL.

XMLNode.XQL

This is the solution to get all relationship item.

var xNode as XmlNode
xNode = uwNode.NextSibling
xmIDRefs = xNode.GetAttribute(“idrefs”)