Loading XML Document into Arrays

Results 1 to 2 of 2

Thread: Loading XML Document into Arrays

  1. #1
    Join Date
    Dec 1969

    Default Loading XML Document into Arrays

    I have an XML document with the following DTD<BR><BR>&#060;!ELEMENT PackSlipList (PackSlip*)&#062;<BR>&#060;!ELEMENT PackSlip (ShipTo, Item*)&#062;<BR>&#060;!ELEMENT ShipTo (Name, Address1, Address2?, Address3?, City, State, Zip)&#062;<BR>&#060;!ELEMENT Item (ItemNumber, Description, Quantity, NumPerPack)&#062;<BR><BR>I need to load all of the data into Arrays so that I can easily separate all of the information that goes with a particular packing slip. I&#039;m using Visual Basic, but anything from pseudo-code to ASP will help. Thanks!

  2. #2
    Doug Setzer Guest

    Default RE: Loading XML Document into Arrays

    You are going to need to load the XML document (either from a string or from a file). Once you have opened it, you want to get a variable that contains all of the child nodes for PackSlipList (which should be a collection [NodeList] of "PackSlip"s).<BR><BR>You can loop through that and populate a 2 dimensional array or an array in an array.<BR><BR>I&#039;m confused, though, why you just don&#039;t read from the XMLDocument the entire time. You&#039;ve went through the trouble of building the XML support. It already contains the hierarchial information of the PackSlips/Items. Just a thought.<BR><BR>Something like the following code should work for you:<BR><BR><BR><BR>Dim iCnt<BR>Dim oXMLDoc<BR> oXMLDoc.Load sFilenameForXML<BR>Dim oXMLNodes, oXMLNode<BR> Set oXMLNodes = oXMLDoc.selectSingleNode("/PackSlipList").childNodes<BR><BR>Dim arrPackSlips()<BR>Redim arrPackSlips(oXMLNodes.length - 1, 3)<BR> For iCnt = 0 To oXMLNodes.length - 1<BR> Set oXMLNode = oXMLNodes.item(iCnt).selectSingleNode("item")<BR> arrPackSlips(iCnt, 0) = oXMLNode.selectSingleNode("ItemNumber").text<BR> arrPackSlips(iCnt, 1) = oXMLNode.selectSingleNode("Description").text<BR> arrPackSlips(iCnt, 2) = oXMLNode.selectSingleNode("Quantity").text<BR> arrPackSlips(iCnt, 3) = oXMLNode.selectSingleNode("NumPerPack").text<BR> Set oXMLNode = Nothing<BR> Next iCnt<BR><BR> Set oXMLNode = Nothing<BR> Set oXMLDoc = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts