RWayneH
asked on
Pull value from XML that has four of the same <Profile> in it?
I use the following code is what I use to get a value from an xml file (attached) however now I am trying to get some data from the PurchaseOrder/Profile/ but there are 4 different Profiles? How would I get the SoldTo, ShipTo values when there are 4 Profiles to choose from? In the example xml all the values are the same, but they will have different values. I am trying to use: Set node1, to pulled the 60520 value from the SoldTo (node and node2 work fine. Any ideas? Is the Profile[0] = the first, Profile[1] = the second ? as in the node2 that is working?
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
xmlDoc.Load(ListOfFiles)
On Error Resume Next
Set node = xmlDoc.SelectSingleNode("Envelope/PurchaseOrder/Header/RequestedDate/text()")
Set node1 = xmlDoc.SelectSingleNode("Envelope/PurchaseOrder/Profile/Type/Code/text()")
DoRec = node1.NodeValue
If node > 1 Then
ReqDT = node.NodeValue
MyMonth=Month(ReqDT)'grabs month value from NewDate
MyDay=Day(ReqDT) 'grabs day value from NewDate
MyYear=Year(ReqDT) 'grabs year value from NewDate
FormattedDate=MyMonth&"/"&MyDay&"/"&MyYear 'concatinates values into a new value called FormattedDate
If FormattedDate = "12/30/1899" Then
FormattedDate = ""
End If
DataTable.Value("ReqDT","Global") = FormattedDate
End If
Err.Clear
Set node2 = xmlDoc.SelectSingleNode("Envelope/PurchaseOrder/Profile[0]/Code/text()")
DOR2 = node2.NodeValue
DataTable.Value("DOR","Global") = DOR2
002.xml
ASKER
Not following... all the XMLDOM stuff, but //n:Profile[n:Type='ShipTp ']
So how would this look in the Set node1 statement? it would be something like:
Set node1 = xmlDoc.SelectSingleNode("E nvelope/Pu rchaseOrde r/ //n:Profile[n:Type='ShipTp ']/text()" ) ???
So how would this look in the Set node1 statement? it would be something like:
Set node1 = xmlDoc.SelectSingleNode("E
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your help lead me to:
that worked. Not using the [0] or [1] anymore is much better way, in case one of the 4 Profiles is not there and it shifts the seq.
Appreciate the help.
Set node1 = xmlDoc.SelectSingleNode("Envelope/PurchaseOrder/Profile[Type='ShipTo']/Code/text()") 'get ShipTo from xml
DoRec = node1.NodeValue
that worked. Not using the [0] or [1] anymore is much better way, in case one of the 4 Profiles is not there and it shifts the seq.
Appreciate the help.
ASKER
Sorry for the delay in closing this question. Thanks for the help!!!
Open in new window
BTW, "Microsoft.XMLDOM" is the progid for a very ancient implementation of MSXML. I'd recommend to use "MSXML2.DOMDocument.6.0" instead.
But then you need to explicitly declare the namespace alias and use it in the queries.
Open in new window
Open in new window