Connecting Tech Pros Worldwide Forums | Help | Site Map

XML Functions problem

Bryan Dickerson
Guest
 
Posts: n/a
#1: Nov 23 '05
I know that this structure is accurate, so I'm trying a test to see if what
I get back from this:

Dim xElem As Xml.XmlElement
Dim sVal As String
xElem = xmlPO.GetElementById("Body/PurchaseOrder/OrderHeader")
sVal = xElem.GetAttribute("BuyerOrderNumber")

Does anyone see an obvious problem, if, as I said, the XML hierarchy is
correct?

--
TFWBWY...A



zacks@construction-imaging.com
Guest
 
Posts: n/a
#2: Nov 23 '05

re: XML Functions problem


Possibly:

xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
sVal = xElem.GetAttribute("@BuyerOrderNumber")

Bryan Dickerson
Guest
 
Posts: n/a
#3: Nov 23 '05

re: XML Functions problem


I just stepped thru it and watched the "Autos" box a bit more closely and
xElem is still set to "Nothing" after the first statement below and gets
"Object reference not set to an instance of the object" as an error message.
I tried "Dim"-ming xElem to a New XML.XmlElement, but the build didn't work
and said "Overload resolution failed because no 'New' is accessible."

Hmmm...

Any ideas?

<zacks@construction-imaging.com> wrote in message
news:1132075936.749880.282640@z14g2000cwz.googlegr oups.com...[color=blue]
> Possibly:
>
> xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
> sVal = xElem.GetAttribute("@BuyerOrderNumber")
>[/color]


Chris
Guest
 
Posts: n/a
#4: Nov 23 '05

re: XML Functions problem


Bryan Dickerson wrote:[color=blue]
> I just stepped thru it and watched the "Autos" box a bit more closely and
> xElem is still set to "Nothing" after the first statement below and gets
> "Object reference not set to an instance of the object" as an error message.
> I tried "Dim"-ming xElem to a New XML.XmlElement, but the build didn't work
> and said "Overload resolution failed because no 'New' is accessible."
>
> Hmmm...
>
> Any ideas?
>
> <zacks@construction-imaging.com> wrote in message
> news:1132075936.749880.282640@z14g2000cwz.googlegr oups.com...
>[color=green]
>>Possibly:
>>
>>xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
>>sVal = xElem.GetAttribute("@BuyerOrderNumber")
>>[/color]
>
>
>[/color]

xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
if xElem is nothing then
messagebox.show("You did not find any elements using that xpaht")
else
sVal = xElem.GetAttribute("@BuyerOrderNumber")
end if

You can't new the xelem, it has to be returned by the GetElementById or
a similar function.

Chris
Bryan Dickerson
Guest
 
Posts: n/a
#5: Nov 23 '05

re: XML Functions problem


So that would mean that the GetElementByID function didn't work, right?
Here's a snippet of the XML Doc:

-------------------------------------------------------------------
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<PurchaseOrder>
<OrderHeader>
<BuyerOrderNumber>TestPo1</BuyerOrderNumber>

-------------------------------------------------------------------


"Chris" <no@spam.com> wrote in message
news:ufhhq8g6FHA.3636@TK2MSFTNGP12.phx.gbl...[color=blue]
> Bryan Dickerson wrote:[color=green]
>> I just stepped thru it and watched the "Autos" box a bit more closely and
>> xElem is still set to "Nothing" after the first statement below and gets
>> "Object reference not set to an instance of the object" as an error
>> message. I tried "Dim"-ming xElem to a New XML.XmlElement, but the build
>> didn't work and said "Overload resolution failed because no 'New' is
>> accessible."
>>
>> Hmmm...
>>
>> Any ideas?
>>
>> <zacks@construction-imaging.com> wrote in message
>> news:1132075936.749880.282640@z14g2000cwz.googlegr oups.com...
>>[color=darkred]
>>>Possibly:
>>>
>>>xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
>>>sVal = xElem.GetAttribute("@BuyerOrderNumber")
>>>[/color]
>>
>>
>>[/color]
>
> xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
> if xElem is nothing then
> messagebox.show("You did not find any elements using that xpaht")
> else
> sVal = xElem.GetAttribute("@BuyerOrderNumber")
> end if
>
> You can't new the xelem, it has to be returned by the GetElementById or a
> similar function.
>
> Chris[/color]


Chris
Guest
 
Posts: n/a
#6: Nov 23 '05

re: XML Functions problem


Bryan Dickerson wrote:[color=blue]
> So that would mean that the GetElementByID function didn't work, right?
> Here's a snippet of the XML Doc:
>
> -------------------------------------------------------------------
> <SOAP-ENV:Envelope
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Body>
> <PurchaseOrder>
> <OrderHeader>
> <BuyerOrderNumber>TestPo1</BuyerOrderNumber>
>
> -------------------------------------------------------------------
>
>
> "Chris" <no@spam.com> wrote in message
> news:ufhhq8g6FHA.3636@TK2MSFTNGP12.phx.gbl...
>[color=green]
>>Bryan Dickerson wrote:
>>[color=darkred]
>>>I just stepped thru it and watched the "Autos" box a bit more closely and
>>>xElem is still set to "Nothing" after the first statement below and gets
>>>"Object reference not set to an instance of the object" as an error
>>>message. I tried "Dim"-ming xElem to a New XML.XmlElement, but the build
>>>didn't work and said "Overload resolution failed because no 'New' is
>>>accessible."
>>>
>>>Hmmm...
>>>
>>>Any ideas?
>>>
>>><zacks@construction-imaging.com> wrote in message
>>>news:1132075936.749880.282640@z14g2000cwz.googl egroups.com...
>>>
>>>
>>>>Possibly:
>>>>
>>>>xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
>>>>sVal = xElem.GetAttribute("@BuyerOrderNumber")
>>>>
>>>
>>>
>>>[/color]
>>xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
>>if xElem is nothing then
>>messagebox.show("You did not find any elements using that xpaht")
>>else
>>sVal = xElem.GetAttribute("@BuyerOrderNumber")
>>end if
>>
>>You can't new the xelem, it has to be returned by the GetElementById or a
>>similar function.
>>
>>Chris[/color]
>
>
>[/color]

Yes that it what it means... I've used xpath very little but if you
take out the "SOAP-ENV:" in front of body, does it work?

chris
Bryan Dickerson
Guest
 
Posts: n/a
#7: Nov 23 '05

re: XML Functions problem


If I take out the SOAP-ENV, the functions to load the XML document don't
work.[color=blue]
>
> Yes that it what it means... I've used xpath very little but if you take
> out the "SOAP-ENV:" in front of body, does it work?
>
> chris[/color]


Joseph Ferris
Guest
 
Posts: n/a
#8: Nov 23 '05

re: XML Functions problem


Bryan,

You don't want to remove the namespace from the node. What you need to
do is inform the parser of the namespace. You would think that it
would be smart enough to handle this on its own...

What you need to do is define the namespace in an XmlNamespaceManager
instance. Here is a sample:

http://samples.gotdotnet.com/quickst...NameSpace.aspx

Once you set up the XmlNamespaceManager, you should be able to access
the element with:
//SOAP-ENV:Body/PurchaseOrder/OrderHeader

Let me know if that works for you. HTH!

Joseph

Bryan Dickerson
Guest
 
Posts: n/a
#9: Nov 23 '05

re: XML Functions problem


Does it make any difference that there isn't the "<?xml version="1.0"> at
the beginning of the document??

"Chris" <no@spam.com> wrote in message
news:%23qRoyph6FHA.3636@TK2MSFTNGP09.phx.gbl...[color=blue]
> Bryan Dickerson wrote:[color=green]
>> So that would mean that the GetElementByID function didn't work, right?
>> Here's a snippet of the XML Doc:
>>
>> -------------------------------------------------------------------
>> <SOAP-ENV:Envelope
>> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
>> <SOAP-ENV:Body>
>> <PurchaseOrder>
>> <OrderHeader>
>> <BuyerOrderNumber>TestPo1</BuyerOrderNumber>
>>
>> -------------------------------------------------------------------
>>
>>
>> "Chris" <no@spam.com> wrote in message
>> news:ufhhq8g6FHA.3636@TK2MSFTNGP12.phx.gbl...
>>[color=darkred]
>>>Bryan Dickerson wrote:
>>>
>>>>I just stepped thru it and watched the "Autos" box a bit more closely
>>>>and xElem is still set to "Nothing" after the first statement below and
>>>>gets "Object reference not set to an instance of the object" as an error
>>>>message. I tried "Dim"-ming xElem to a New XML.XmlElement, but the build
>>>>didn't work and said "Overload resolution failed because no 'New' is
>>>>accessible."
>>>>
>>>>Hmmm...
>>>>
>>>>Any ideas?
>>>>
>>>><zacks@construction-imaging.com> wrote in message
>>>>news:1132075936.749880.282640@z14g2000cwz.goog legroups.com...
>>>>
>>>>
>>>>>Possibly:
>>>>>
>>>>>xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
>>>>>sVal = xElem.GetAttribute("@BuyerOrderNumber")
>>>>>
>>>>
>>>>
>>>>
>>>xElem = xmlPO.GetElementById("/Body/PurchaseOrder/OrderHeader")
>>>if xElem is nothing then
>>>messagebox.show("You did not find any elements using that xpaht")
>>>else
>>>sVal = xElem.GetAttribute("@BuyerOrderNumber")
>>>end if
>>>
>>>You can't new the xelem, it has to be returned by the GetElementById or a
>>>similar function.
>>>
>>>Chris[/color]
>>
>>
>>[/color]
>
> Yes that it what it means... I've used xpath very little but if you take
> out the "SOAP-ENV:" in front of body, does it work?
>
> chris[/color]


Bryan Dickerson
Guest
 
Posts: n/a
#10: Nov 23 '05

re: XML Functions problem


My reply from yesterday afternoon, was posted before I read this note. I
think this will help, but I need some more time to digest it. I'll let you
know, though. Thanx for the help!

"Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
news:1132090990.431058.65400@o13g2000cwo.googlegro ups.com...[color=blue]
> Bryan,
>
> You don't want to remove the namespace from the node. What you need to
> do is inform the parser of the namespace. You would think that it
> would be smart enough to handle this on its own...
>
> What you need to do is define the namespace in an XmlNamespaceManager
> instance. Here is a sample:
>
> http://samples.gotdotnet.com/quickst...NameSpace.aspx
>
> Once you set up the XmlNamespaceManager, you should be able to access
> the element with:
> //SOAP-ENV:Body/PurchaseOrder/OrderHeader
>
> Let me know if that works for you. HTH!
>
> Joseph
>[/color]


Joseph Ferris
Guest
 
Posts: n/a
#11: Nov 23 '05

re: XML Functions problem


Not a problem, Bryan. Just post back here if it doesn't. I am pretty
sure that will take care of your problem. If not, I'll look into it a
little more.

Joseph

Bryan Dickerson
Guest
 
Posts: n/a
#12: Nov 23 '05

re: XML Functions problem


Ok, this is the code that I've come up with:

xTest.LoadXml(sData)
xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
xNSM.AddNamespace("SOAP-ENV", "http://tempuri.org/SOAP-ENV")

xElem =
xTest.GetElementById("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber")
sVal = xElem.Value

But I'm still getting the error: "Object reference not set to an instance of
an object." on the last line of code that I included here. I'm still not
getting anything returned from the GetElementById function.

What now?

"Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
news:1132090990.431058.65400@o13g2000cwo.googlegro ups.com...[color=blue]
> Bryan,
>
> You don't want to remove the namespace from the node. What you need to
> do is inform the parser of the namespace. You would think that it
> would be smart enough to handle this on its own...
>
> What you need to do is define the namespace in an XmlNamespaceManager
> instance. Here is a sample:
>
> http://samples.gotdotnet.com/quickst...NameSpace.aspx
>
> Once you set up the XmlNamespaceManager, you should be able to access
> the element with:
> //SOAP-ENV:Body/PurchaseOrder/OrderHeader
>
> Let me know if that works for you. HTH!
>
> Joseph
>[/color]


Joseph Ferris
Guest
 
Posts: n/a
#13: Nov 23 '05

re: XML Functions problem


Bryan,

You are almost there... ;-) Inline.

Bryan Dickerson wrote:
[color=blue]
> xTest.LoadXml(sData)
> xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
> xNSM.AddNamespace("SOAP-ENV", "http://tempuri.org/SOAP-ENV")[/color]

Here is your first problem. When you add the namespace, it needs to
match the namespace declaration in the XML. It uses it is a lookup, so
if both parts don't match, it fails. Change this line in your code to:

xNSM.AddNamespace("SOAP-ENV",
"http://schemas.xmlsoap.org/soap/envelope/")
[color=blue]
> xElem =
> xTest.GetElementById("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber")
> sVal = xElem.Value[/color]

The problem here is that you need to query within the context of the
XmlNamespaceManager. To do this, use SelectSingleNode(), like this:

Dim nodRetrieve As XmlNode
nodRetrieve =
xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
xNSM)
[color=blue]
> But I'm still getting the error: "Object reference not set to an instance of
> an object." on the last line of code that I included here. I'm still not
> getting anything returned from the GetElementById function.
>
> What now?[/color]

So, I made a quick and dirty sample using the snippet of the XML that
you made along with a modified version of the source you posted. Mine
looks like this:

Dim xTest As New XmlDocument
Dim sData As String = _
"<SOAP-ENV:Envelope
xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<SOAP-ENV:Body>" & _
"<PurchaseOrder>" & _
"<OrderHeader> " & _
"<BuyerOrderNumber>TestPo1</BuyerOrderNumber> " & _
"</OrderHeader> " & _
"</PurchaseOrder>" & _
"</SOAP-ENV:Body>" & _
"</SOAP-ENV:Envelope>"

Dim xNSM As System.Xml.XmlNamespaceManager
Dim xElem As XmlElement
Dim sVal As String

xTest.LoadXml(sData)
xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
xNSM.AddNamespace("SOAP-ENV",
"http://schemas.xmlsoap.org/soap/envelope/")

Dim nodRetrieve As XmlNode
nodRetrieve =
xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
xNSM)
sVal = nodRetrieve.InnerText

Let me know if that gets it working for you!

Joseph

Bryan Dickerson
Guest
 
Posts: n/a
#14: Nov 23 '05

re: XML Functions problem


You're a genius!! "Thank You" * 1000 !! That finally gets the log-jam
cleared. Now, I just need to go back and "get to know" the code a bit
better. Nonetheless, thanx again!

"Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
news:1132170275.374170.68480@g49g2000cwa.googlegro ups.com...[color=blue]
> Bryan,
>
> You are almost there... ;-) Inline.
>
> Bryan Dickerson wrote:
>[color=green]
>> xTest.LoadXml(sData)
>> xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
>> xNSM.AddNamespace("SOAP-ENV", "http://tempuri.org/SOAP-ENV")[/color]
>
> Here is your first problem. When you add the namespace, it needs to
> match the namespace declaration in the XML. It uses it is a lookup, so
> if both parts don't match, it fails. Change this line in your code to:
>
> xNSM.AddNamespace("SOAP-ENV",
> "http://schemas.xmlsoap.org/soap/envelope/")
>[color=green]
>> xElem =
>> xTest.GetElementById("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber")
>> sVal = xElem.Value[/color]
>
> The problem here is that you need to query within the context of the
> XmlNamespaceManager. To do this, use SelectSingleNode(), like this:
>
> Dim nodRetrieve As XmlNode
> nodRetrieve =
> xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
> xNSM)
>[color=green]
>> But I'm still getting the error: "Object reference not set to an instance
>> of
>> an object." on the last line of code that I included here. I'm still not
>> getting anything returned from the GetElementById function.
>>
>> What now?[/color]
>
> So, I made a quick and dirty sample using the snippet of the XML that
> you made along with a modified version of the source you posted. Mine
> looks like this:
>
> Dim xTest As New XmlDocument
> Dim sData As String = _
> "<SOAP-ENV:Envelope
> xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
> "<SOAP-ENV:Body>" & _
> "<PurchaseOrder>" & _
> "<OrderHeader> " & _
> "<BuyerOrderNumber>TestPo1</BuyerOrderNumber> " & _
> "</OrderHeader> " & _
> "</PurchaseOrder>" & _
> "</SOAP-ENV:Body>" & _
> "</SOAP-ENV:Envelope>"
>
> Dim xNSM As System.Xml.XmlNamespaceManager
> Dim xElem As XmlElement
> Dim sVal As String
>
> xTest.LoadXml(sData)
> xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
> xNSM.AddNamespace("SOAP-ENV",
> "http://schemas.xmlsoap.org/soap/envelope/")
>
> Dim nodRetrieve As XmlNode
> nodRetrieve =
> xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
> xNSM)
> sVal = nodRetrieve.InnerText
>
> Let me know if that gets it working for you!
>
> Joseph
>[/color]


Bryan Dickerson
Guest
 
Posts: n/a
#15: Nov 23 '05

re: XML Functions problem


Next question: How do I reference this line?

<BuyerReferences RefType="DepartmentNumber">951</BuyerReferences>

TIA!

"Bryan Dickerson" <txprphan@netscape.net> wrote in message
news:uPnhTwu6FHA.3592@TK2MSFTNGP12.phx.gbl...[color=blue]
> You're a genius!! "Thank You" * 1000 !! That finally gets the log-jam
> cleared. Now, I just need to go back and "get to know" the code a bit
> better. Nonetheless, thanx again!
>
> "Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
> news:1132170275.374170.68480@g49g2000cwa.googlegro ups.com...[color=green]
>> Bryan,
>>
>> You are almost there... ;-) Inline.
>>
>> Bryan Dickerson wrote:
>>[color=darkred]
>>> xTest.LoadXml(sData)
>>> xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
>>> xNSM.AddNamespace("SOAP-ENV", "http://tempuri.org/SOAP-ENV")[/color]
>>
>> Here is your first problem. When you add the namespace, it needs to
>> match the namespace declaration in the XML. It uses it is a lookup, so
>> if both parts don't match, it fails. Change this line in your code to:
>>
>> xNSM.AddNamespace("SOAP-ENV",
>> "http://schemas.xmlsoap.org/soap/envelope/")
>>[color=darkred]
>>> xElem =
>>> xTest.GetElementById("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber")
>>> sVal = xElem.Value[/color]
>>
>> The problem here is that you need to query within the context of the
>> XmlNamespaceManager. To do this, use SelectSingleNode(), like this:
>>
>> Dim nodRetrieve As XmlNode
>> nodRetrieve =
>> xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
>> xNSM)
>>[color=darkred]
>>> But I'm still getting the error: "Object reference not set to an
>>> instance of
>>> an object." on the last line of code that I included here. I'm still
>>> not
>>> getting anything returned from the GetElementById function.
>>>
>>> What now?[/color]
>>
>> So, I made a quick and dirty sample using the snippet of the XML that
>> you made along with a modified version of the source you posted. Mine
>> looks like this:
>>
>> Dim xTest As New XmlDocument
>> Dim sData As String = _
>> "<SOAP-ENV:Envelope
>> xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
>> "<SOAP-ENV:Body>" & _
>> "<PurchaseOrder>" & _
>> "<OrderHeader> " & _
>> "<BuyerOrderNumber>TestPo1</BuyerOrderNumber> " & _
>> "</OrderHeader> " & _
>> "</PurchaseOrder>" & _
>> "</SOAP-ENV:Body>" & _
>> "</SOAP-ENV:Envelope>"
>>
>> Dim xNSM As System.Xml.XmlNamespaceManager
>> Dim xElem As XmlElement
>> Dim sVal As String
>>
>> xTest.LoadXml(sData)
>> xNSM = New Xml.XmlNamespaceManager(xTest.NameTable)
>> xNSM.AddNamespace("SOAP-ENV",
>> "http://schemas.xmlsoap.org/soap/envelope/")
>>
>> Dim nodRetrieve As XmlNode
>> nodRetrieve =
>> xTest.SelectSingleNode("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerOrderNumber",
>> xNSM)
>> sVal = nodRetrieve.InnerText
>>
>> Let me know if that gets it working for you!
>>
>> Joseph
>>[/color]
>
>[/color]


Joseph Ferris
Guest
 
Posts: n/a
#16: Nov 23 '05

re: XML Functions problem


I am not sure what the full XPath is, since I don't know your full body
structure. However, I am assuming that you are wondering how to find a
node for a specific attribute value, correct?

If so, your XPath would be something like:
//SOAP-ENV:Body/PurchaseOrder/BuyerReferences[@RefType='951']

Note, that I just assumed that was where your node would be. You will
have to adjust that XPath based upon your structure.

Joseph

Bryan Dickerson
Guest
 
Posts: n/a
#17: Nov 23 '05

re: XML Functions problem


This is the xml snippet:

-------------------------------------------------------------------
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<PurchaseOrder>
<OrderHeader>
<BuyerOrderNumber>TestPo1</BuyerOrderNumber>
<BuyerReferences
RefType="DepartmentNumber">951</BuyerReferences>
<BuyerReferences
RefType="InternalVendorNumber">123324</BuyerReferences>
-------------------------------------------------------------------
.... and my goal is to grab the "951" into a variable. For that matter how
would I grab all the BuyerReferences?

"Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
news:1132176966.408450.14410@g47g2000cwa.googlegro ups.com...[color=blue]
>I am not sure what the full XPath is, since I don't know your full body
> structure. However, I am assuming that you are wondering how to find a
> node for a specific attribute value, correct?
>
> If so, your XPath would be something like:
> //SOAP-ENV:Body/PurchaseOrder/BuyerReferences[@RefType='951']
>
> Note, that I just assumed that was where your node would be. You will
> have to adjust that XPath based upon your structure.
>
> Joseph
>[/color]


Joseph Ferris
Guest
 
Posts: n/a
#18: Nov 23 '05

re: XML Functions problem



Bryan Dickerson wrote:[color=blue]
> This is the xml snippet:
>
> -------------------------------------------------------------------
> <SOAP-ENV:Envelope
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
> <SOAP-ENV:Body>
> <PurchaseOrder>
> <OrderHeader>
> <BuyerOrderNumber>TestPo1</BuyerOrderNumber>
> <BuyerReferences
> RefType="DepartmentNumber">951</BuyerReferences>
> <BuyerReferences
> RefType="InternalVendorNumber">123324</BuyerReferences>
> -------------------------------------------------------------------
> ... and my goal is to grab the "951" into a variable. For that matter how
> would I grab all the BuyerReferences?[/color]

To grab "951", change the XPath from the sample I had posted to:

//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerReferences[@RefType='DepartmentNumber']

To get all of the BuyerReferences, it is a little different. You are
selecting multiple nodes, so you can get them all by changing the
SelectSingleNode() to SelectNodes(). From there, you can iterate
through them. Like this:

Dim ndlBuyerReferences As XmlNodeList
Dim nodBuyerReference As XmlNode

ndlBuyerReferences =
xTest.SelectNodes("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerReferences",

xNSM)

For Each nodBuyerReference In ndlBuyerReferences

'// Your individual nodBuyerReference is here.

Next

Joseph

Bryan Dickerson
Guest
 
Posts: n/a
#19: Nov 23 '05

re: XML Functions problem


Thank you again! Now if I can beg the answer to one more question: Using
my snippet as an example, I created the NodeList and looped thru the Nodes
successfully, but where is the "RefType" value hidden in the Node?

TIA!

"Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
news:1132235683.073929.90480@o13g2000cwo.googlegro ups.com...[color=blue]
>
> Bryan Dickerson wrote:[color=green]
>> This is the xml snippet:
>>
>> -------------------------------------------------------------------
>> <SOAP-ENV:Envelope
>> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
>> <SOAP-ENV:Body>
>> <PurchaseOrder>
>> <OrderHeader>
>> <BuyerOrderNumber>TestPo1</BuyerOrderNumber>
>> <BuyerReferences
>> RefType="DepartmentNumber">951</BuyerReferences>
>> <BuyerReferences
>> RefType="InternalVendorNumber">123324</BuyerReferences>
>> -------------------------------------------------------------------
>> ... and my goal is to grab the "951" into a variable. For that matter
>> how
>> would I grab all the BuyerReferences?[/color]
>
> To grab "951", change the XPath from the sample I had posted to:
>
> //SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerReferences[@RefType='DepartmentNumber']
>
> To get all of the BuyerReferences, it is a little different. You are
> selecting multiple nodes, so you can get them all by changing the
> SelectSingleNode() to SelectNodes(). From there, you can iterate
> through them. Like this:
>
> Dim ndlBuyerReferences As XmlNodeList
> Dim nodBuyerReference As XmlNode
>
> ndlBuyerReferences =
> xTest.SelectNodes("//SOAP-ENV:Body/PurchaseOrder/OrderHeader/BuyerReferences",
>
> xNSM)
>
> For Each nodBuyerReference In ndlBuyerReferences
>
> '// Your individual nodBuyerReference is here.
>
> Next
>
> Joseph
>[/color]


Joseph Ferris
Guest
 
Posts: n/a
#20: Nov 23 '05

re: XML Functions problem


Bryan,

Not a problem at all...

"RefType" is an attribute to a node in your document. You can find it
in the Attributes collection of the XmlNode, which is an
XmlAttributeCollection object.

To iterate through them, you can use a similar For Each construct.

For Each nodBuyerReference In ndlBuyerReferences

'// Your node is here in nodBuyerReference.

Dim attBuyerReference As XmlAttribute

For Each attBuyerReference In nodBuyerReference.Attributes

'// Your attribute is here, in attBuyerReference.

Next

Next

HTH!

Joseph

Bryan Dickerson
Guest
 
Posts: n/a
#21: Nov 23 '05

re: XML Functions problem


I'm not worthy! I'm not worthy! I'm not worthy! Thanx a mil!

"Joseph Ferris" <joseph.ferris@gmail.com> wrote in message
news:1132247189.965769.280500@z14g2000cwz.googlegr oups.com...[color=blue]
> Bryan,
>
> Not a problem at all...
>
> "RefType" is an attribute to a node in your document. You can find it
> in the Attributes collection of the XmlNode, which is an
> XmlAttributeCollection object.
>
> To iterate through them, you can use a similar For Each construct.
>
> For Each nodBuyerReference In ndlBuyerReferences
>
> '// Your node is here in nodBuyerReference.
>
> Dim attBuyerReference As XmlAttribute
>
> For Each attBuyerReference In nodBuyerReference.Attributes
>
> '// Your attribute is here, in attBuyerReference.
>
> Next
>
> Next
>
> HTH!
>
> Joseph
>[/color]


Closed Thread