Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlDocument NameSpace Trouble

Status
Not open for further replies.

klornpallier

Technical User
Aug 28, 2002
98
GB
Hi,

I have the xml below which I am reading using XML Document. My code also below works fine if I take the namespace out of the xml but I cannot seem to get the reader right with the NameSpace. Advice would be appreciated.

<?xml version="1.0" encoding="UTF-8" ?>
- <iPOSImports xmlns=" xmlns:xsi="- <Kofax>
- <Invoices>
- <Invoice>
<Company>SHA</Company>
<SupplierAccntCode>8SUPP</SupplierAccntCode>
<SupplierInvoiceNo>ABC123456789</SupplierInvoiceNo>
<InvoiceDate>2010-01-01</InvoiceDate>
<TotalValue>117.50</TotalValue>
<OrderNo>123456789</OrderNo>
<Barcode>ABCDEF1234567890</Barcode>
<DocumentType>I</DocumentType>
</Invoice>
</Invoices>
</Kofax>
</iPOSImports>

---------------------
My Code

' Declare a variable named InvoiceXmlDocument of type XmlDocument.
Dim InvoiceXmlDocument As XmlDocument
' Instantiate a new XmlDocument object assigning it to the 'InvoiceXmlDocument variable.
InvoiceXmlDocument = New XmlDocument

' Call the OrderXmlDocument object's Load method
' passing it the file path to a .xml file that defines order information.
InvoiceXmlDocument.Load(FullName)
' Declare a variable named theXPathNavigator of type XPathNavigator.
Dim theXPathNavigator As XPathNavigator
' Call the OrderXmlDocument object's CreateNavigator method
' assigning the resulting XPathNavigator object to the 'theXPathNavigator' variable.
theXPathNavigator = InvoiceXmlDocument.CreateNavigator

' Declare a variable named theXPathExpression of type XPathExpression.
Dim theXPathExpression As XPathExpression
' Call theXPathNavigator object's Compile method passing it a query string;
' assign the resulting XPathPression object to the 'theXPathExpression' variable.

theXPathExpression = theXPathNavigator.Compile("//Kofax/Invoices/Invoice/Company")

' Declare a variable named nodes of type XPathNodeIterator.
Dim nodeHead As XPathNodeIterator
' Call theXPathNavigator's Select method passing it theXPathExpression;
' assign the resulting XPathNodeIterator object to the 'nodes' variable.

nodeHead = theXPathNavigator.Select(theXPathExpression)
' Iterate through the Item nodes writing out each items details,

While (nodeHead.MoveNext())
Console.Write("Company: " & nodeHead.Current.Value.ToString & Environment.NewLine)
Company = nodeHead.Current.Value.ToString
 
I've taken out comments (slightly distractive to my eye)
[tt]
'... etc etc
Dim theXPathExpression As XPathExpression
theXPathExpression = theXPathNavigator.Compile("//[blue]ns:[/blue]Kofax/[blue]ns:[/blue]Invoices/[blue]ns:[/blue]Invoice/[blue]ns:[/blue]Company")
[blue]Dim xmlnsManager As XmlNamespaceManager = New XmlNamespaceManager(theXPathNavigator.NameTable)
xmlnsManager.AddNamespace("ns", "[ignore][/ignore]")
theXPathExpression.SetContext(xmlnsManager)[/blue]
Dim nodeHead As XPathNodeIterator
nodeHead = theXPathNavigator.Select(theXPathExpression)
'etc etc ...
[/tt]
And then you can put back the comments.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top