XML Parsing Difficulties

Started by bmclellan, April 09, 2020, 03:16:56 PM

Previous topic - Next topic

bmclellan

Hello, I have an XML document that looks like below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Stores xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <store storeID="877389504">
      <dynamicMenu>Yes</dynamicMenu>
      <dynamicExt>11111</dynamicExt>
      <dynamicHours>no</dynamicHours>
   </store>
   <store storeID="877389504">
      <dynamicMenu>no</dynamicMenu>
      <dynamicExt>no</dynamicExt>
      <dynamicHours>18</dynamicHours>
   </store>
</Stores>

I am attempting to read this into this into an array to use with the ReportView control. Unfortunately I am having the worst time trying to get the values out of here.
My goal is to have the output
StoreID       dynamicMenu dynamicExt dynamicHours
877389504  yes                11111         yes
877389504  no                 no               18

I think I've tried just about every combination possible, but what I'd like to do is something like below:

strPageContent = fileget(IntakeFileName)   ;This is the XML above
xmlDoc = ObjectCreate("MSXML2.DOMDocument.3.0")
xmlDoc.SetProperty('SelectionLanguage','XPath')
xmlDoc.async = @FALSE
xmlDoc.loadxml( strPageContent )
If xmlDoc.parseError.errorCode != 0
  Message('Invalid XML Files - parseError', xmlDoc.parseError.reason);  ERROR: The following tags were not closed: assembly, file.
  exit
end if

oRoot = xmlDoc.selectNodes('.//store[contains(@storeID,"")]')
StoreNo = oRoot.item(TotalNodes).getAttribute('storeID')

Then get the remaining 3 elements as well, but I'm not sure how to do this easily.
      <dynamicMenu>no</dynamicMenu>
      <dynamicExt>no</dynamicExt>
      <dynamicHours>18</dynamicHours>

I made the mistake of taking the storeNo and then putting that into a
xmlDoc.selectSingleNode(QueryStr) and grabbing the child nodes from that oPC=oStoreNode.childNodes but that just adds too much overhead by searching the doc all over again to get out the child nodes.

Hope someone can help, maybe it's just being so cooped up these days, but soo frustrating!

Thanks everyone!
Barry


JTaylor

See if this gets you back on track...I always strip namespace stuff and the document declaration.   Maybe there is a way to make that work but never has for me and has never been worth the time to me to figure it out.  I assume getting things in an array won't be an issue for you and that the XML stuff was the problem.  If I am wrong let me know.

Jim

Code (winbatch) Select


strPageContent = fileget(IntakeFileName)   ;This is the XML above

strPageContent = ItemRemove(1,xml,">")
strPageContent = StrReplace(xml,' xmlns:xsi="http:://www.w3.org/2001/XMLSchema-instance',"")

xmlDoc = ObjectCreate("MSXML2.DOMDocument.3.0")
xmlDoc.SetProperty('SelectionLanguage','XPath')
xmlDoc.async = @FALSE
xmlDoc.loadxml( strPageContent )
If xmlDoc.parseError.errorCode != 0
  Message('Invalid XML Files - parseError', xmlDoc.parseError.reason);  ERROR: The following tags were not closed: assembly, file.
  exit
end if

oRoot = xmlDoc.selectNodes('.//store[contains(@storeID,"")]')
ForEach oNode in oRoot
  StoreNo = oNode.getAttribute('storeID')
  Menu    = oNode.SelectSingleNode("dynamicMenu").Text
  Ext     = oNode.SelectSingleNode("dynamicExt").Text
  Hours   = oNode.SelectSingleNode("dynamicHours").Text
  Message("Store",StoreNo:@CRLF:Menu:@CRLF:Ext:@CRLF:Hours)
Next

ObjectClose(xmlDoc)


bmclellan

That was it Jim!!

Thanks so much, I could not wrap my head around it for the life of me!!



Barry

JTaylor