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!

2
  • 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: w3schools.com/xml/default.asp. Commented Jun 25, 2012 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. Will add details once resolved. Commented Jun 25, 2012 at 19:24

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.