Link to home
Start Free TrialLog in
Avatar of RWayneH
RWayneHFlag for United States of America

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		

Open in new window

002.xml
Avatar of zc2
zc2
Flag of United States of America image

You can take to the account the content of the subnodes when you do your selectSingleNode() call, like
//Profile[Type='ShipTo']

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.
xmlDoc.setProperty "SelectionNamespaces",  "xmlns:n='http://www.ofdaxml.org/schema'"

Open in new window

//n:Profile[n:Type='ShipTo']

Open in new window

Avatar of RWayneH

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("Envelope/PurchaseOrder/ //n:Profile[n:Type='ShipTp']/text()")  ???
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RWayneH

ASKER

Your help lead me to:
Set node1 = xmlDoc.SelectSingleNode("Envelope/PurchaseOrder/Profile[Type='ShipTo']/Code/text()") 'get ShipTo from xml
		DoRec = node1.NodeValue

Open in new window


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.
Avatar of RWayneH

ASKER

Sorry for the delay in closing this question.  Thanks for the help!!!