Why can I only extract XML data from the first node of the XML-doc?

So I have an XML-doc “xdoc” from where I want to extract some values:
Company [Value]
CEO [Value]
TelephoneNo [Value]
Address [Value]
It looks something like this (I had to replace “<” and “>” with “(” and “)” because the forum would lose the formatting, and I had to put ind underscores instead of spaces…

(FormInstance)
_____ (Pages)
__________ (Page)
_______________ (Pagenumber)1(/Pagenumber)
_______________ (Fields)
____________________ (Field)
_________________________ (Id)10265061(/Id)
_________________________ (Name)Company(/Name)
_________________________ (Value)ACME(/Value)
____________________ (/Field)
____________________ (Field)
_________________________ (Id)10265062(/Id)
_________________________ (Name)CEO(/Name)
_________________________ (Value)John Doe(/Value)
____________________ (/Field)
_______________ (/Fields)
__________ (/Page)
__________ (Page)
_______________ (Pagenumber)2(/Pagenumber)
_______________ (Fields)
____________________ (Field)
_________________________ (Id)10265061(/Id)
______________________________ (Name)TelephoneNo(/Name)
______________________________ (Value)555-123321(/Value)
____________________ (/Field)
____________________ (Field)
_________________________ (Id)10265062(/Id)
_________________________ (Name)Address(/Name)
_________________________ (Value)5 Oak St.(/Value)
____________________ (/Field)
_______________ (/Fields)
__________ (/Page)
_____ (/Pages)
(/FormInstance)

I can extract the values of Company name and CEO like this, but the other two values I cannot get:

ForEach item in xdoc.Element(“FormInstance”).Element(“Pages”).Element(“Page”).Element(“Fields”).Elements(“Field”)

if item.Element("Name").Value = "**Company**"
	strCompany=item.Element("Value").Value

if item.Element("Name").Value = "**CEO**"
	strCEO=item.Element("Value").Value

if item.Element("Name").Value = "**Address**"
	strAddress=item.Element("Value").Value

if item.Element("Name").Value = "**TelephoneNo**"
	strTelephoneNo=item.Element("Value").Value

I guess this is because “Address” and “TelephoneNo” are tagged under another (Page)(/Page), but for the life of me I don’t know my way around this.

I hope my problem is understandable, and someone knows what to do :slight_smile:
Best regards, Mikkel

So I have found a solution, which is a loop within a loop like this:

ForEach Pageitem in xdoc.Element(“FormInstance”).Element(“Pages”).Elements(“Page”)
{
ForEach Fielditem in item.Element(“Fields”).Elements(“Field”)
if Fielditem.Element(“Name”).Value = “Company”
strCompany=item.Element(“Value”).Value

if Fielditem.Element(“Name”).Value = “CEO
strCEO=item.Element(“Value”).Value

if Fielditem.Element(“Name”).Value = “Address
strAddress=item.Element(“Value”).Value

if Fielditem.Element(“Name”).Value = “TelephoneNo
strTelephoneNo=item.Element(“Value”).Value

}
However, this method is SUPER SLOW, as it enumerates each field item, on all pages, every time it looks for a value.
So I used an index, which in this case was the “Pagenumber” xml-tag, to only search for specific fields on their respective pages:

ForEach Pageitem in xdoc.Element(“FormInstance”).Element(“Pages”).Elements(“Page”)
{
IF Pageitem.Element(“Pagenumber”) = “1”
{
ForEach Fielditem in item.Element(“Fields”).Elements(“Field”)
if Fielditem.Element(“Name”).Value = “Company”
strCompany=item.Element(“Value”).Value

if Fielditem.Element(“Name”).Value = “CEO
strCEO=item.Element(“Value”).Value
}

IF Pageitem.Element(“Pagenumber”) = “2”
if Fielditem.Element(“Name”).Value = “Address
strAddress=item.Element(“Value”).Value

if Fielditem.Element(“Name”).Value = “TelephoneNo
strTelephoneNo=item.Element(“Value”).Value

}
This sped up the proces by 3x…
The process is still slow, and I would appreciate if somebody has a way faster method, that also is not dependant of knowing the pagenumbers in advance.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.