Fordraiders
asked on
xml data to excel spreadsheet in vertical format
I have an xml file i need to import and place in vertical format not horizontal
code:
correct format:
xml: data
Thanks
fordraiders
code:
xmlDoc.LoadXML (reader.responseText)
'''' not working
Set xEmpDetails = xmlDoc.DocumentElement
Set xParent = xEmpDetails.FirstChild
Row = 1
Col = 1
Dim xmlNodeList As IXMLDOMNodeList
Set xmlNodeList = xmlDoc.SelectNodes("/*/*/*") ' i think this is working ? 8/26/2020
For Each xParent In xmlNodeList
For Each xChild In xParent.ChildNodes
Worksheets("xmldata").Cells(Row, Col).value = xChild.Text
Next xChild
Row = Row + 1
Col = Col
Next xParent
current output:correct format:
xml: data
Thanks
fordraiders
Where is the third value coming from?
I would use the XML schema like this:
I would use the XML schema like this:
Public Sub ParseXmlDoument(AXmlDocument As Object, AStartCell As Excel.Range) ' Use correct type instead of object.
Dim Items As IXMLDOMNodeList
Dim Item As Object ' Use correct type instead of object.
Dim ItemName As String
Dim Row As Long
Dim TargetPrice As Long
Set Items = AXmlDocument.SelectNodes("/EsrpPriceRequest/Items")
Row = 0
For Each Item In Items
ItemName = Item.SelectSingleNode("Item").Text
TargetPrice = CLng(Item.SelectSingleNode("TargetPrice").Text)
AStartCell.Offset(Row, 0).Value = ItemName
AStartCell.Offset(Row, 1).Value = TargetPrice
Row = Row + 1
Next Item
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both very very much !!!!
In addition to that, I changed the SelectNodes to target only "items" as parent nodes. This way you will be able to fetch their children (it would work with "/*/*" as well).
Open in new window