infopath and vb net: nodelist and xmldocument

J

Jason Bailey

Hello,

I'm trying to change, or to begin with, show values of various nodes in an
Infopath generated xml file.

I have a simple-ish xml file (see below) and I'm trying to use the code
below. I guess my problems are related to the namspace. I now get an error
for line:
MsgBox(order.SelectSingleNode("my:field4").Value)
(XML null reference exception: object reference not set to an instance of an
object..

Could someone tell me how to correct this code so it will somehow loop
thorugh something in my xml. I just can't get to the point where it does
something with the XML i.e. display it or allow me to edit it.

Thanks
Jason


*******VB code*********

' Create an XmlDocument
Dim myXmlDocument As XmlDocument = New XmlDocument
myXmlDocument.Load(args(0))
Console.WriteLine("XmlDocument loaded with XML data successfully
....")
Console.WriteLine()

'shownode(myXmlDocument.DocumentElement)
Dim nsmgr As XmlNamespaceManager = New
XmlNamespaceManager(myXmlDocument.NameTable)
nsmgr.AddNamespace("my", "urn:samples")

' Dim nodeList As XmlNodeList =
myXmlDocument.SelectNodes("//myFields")

Dim root As XmlElement = myXmlDocument.DocumentElement

Dim nodeList As XmlNodeList =
root.SelectNodes("/my:myFields/my:group1/my:group2", nsmgr)



Dim order As XmlNode
MsgBox(order.SelectSingleNode("my:field4").Value)

For Each order In nodeList
MsgBox(order.SelectSingleNode("my:field4").Value)

Next




******************************XML file....*************
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution
solutionVersion="1.0.0.4" productVersion="11.0.6357" PIVersion="1.0.0.0"
href="file:///D:\Code\source\myform.xsn"
name="urn:schemas-microsoft-com:eek:ffice:infopath:myform:-myXSD-2005-04-19T09-13-09"
?><?mso-application progid="InfoPath.Document"?><my:myFields
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-19T09:13:09" xml:lang="en-gb">
<my:field1>jason</my:field1>
<my:field2>bailey</my:field2>
<my:field3>blah blah blah this is stuff</my:field3>
<my:group1>
<my:group2>
<my:field4>apples</my:field4>
<my:field5>pears</my:field5>
<my:field6>oranges</my:field6>
</my:group2><my:group2>
<my:field4>a1</my:field4>
<my:field5>b1</my:field5>
<my:field6>c1</my:field6>
</my:group2><my:group2>
<my:field4>a</my:field4>
<my:field5>b</my:field5>
<my:field6>c</my:field6>
</my:group2>
</my:group1>
</my:myFields>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top