0

I understand this is not according to standard, however a partner is passing XML to our app that contains spaces in the tags, like so:

<RESPONSE>
  <XYZZYS>
    <XYZZY TAG="INFO">123abc</FIELD>
    <XYZZY TAG="MOAR_INFO">123456abcdef</FIELD>
    <XYZZY TAG="EVEN_MOAR_INFO">1</FIELD>

Normally I would load the XML into an object via getElementsByTagName("*") and get the tag names with item(index).nodeName. The problem is that since spaces aren't supposed to be there, item(index).nodeName ends up being simply XYZZY. This is of course a problem since each of them began with XYZZY.

  • For kicks I tried to replace() the "XYZZY " in item(index).nodeName, but predictably this spawned a 500 error.
  • ResponseXML.preserveWhiteSpace doesn't help.
  • I've thought about manipulating the XML as a string to do the replace, but am not sure if I can load it back into an MSXML object... and it seems a little needlessly-complicated...
  • ...as does simple text-string parsing.

Is there a simple solution I've been unable to find? Links to resources are very much appreciated!

Melina
  • 68
  • 5
  • You probably need to read up on some really basic XML since you clearly aren't aware of the some fundamentals like _attributes_ here is a good place to start: http://w3schools.com/xml/default.asp. – AnthonyWJones Jun 25 '12 at 18:58
  • Thanks, that helps- I just did some poking around now that I have "attributes" as a keyword and found something that may work, including [another StackOverflow question](http://stackoverflow.com/questions/94689/asp-xml-parsing). Will add details once resolved. – Melina Jun 25 '12 at 19:24

1 Answers1

0

Based on this StackOverflow question after a pointer in the right direction from AnthonyWJones, here is an appropriate way to parse this:

Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0") 'creating the parser object
oXML.LoadXML(responseXML.responseText) 'Loading the XML from the response

For Each oNode In oXML.SelectNodes("/RESPONSE/XYZZYS/XYZZY")
  sKey = oNode.GetAttribute("KEY")
  sValue = oNode.Text
  'Printing for proof of retrieval.
  response.write("<br>sKey: " & sKey)
  response.write(" sValue: " & sValue)
Next

Set oXML = Nothing

Note that I simply copied from the linked question and edited as needed.

Community
  • 1
  • 1
Melina
  • 68
  • 5