[Info-vax] Best XML DOM parser?

Richard Maher maher_rj at hotspamnotmail.com
Thu Nov 26 18:14:35 EST 2009


Hi again,

For those VMSers who are finally beginning to tear themselves away from
DEC's wonderful FIMS-compliant IFDL, and are looking at dipping a toe into
Javascript, may I recommend www.w3schools.com or specifically
http://www.w3schools.com/ajax/default.asp if you're confused about Ajax. One
problem I had with it was pulling stuff out of the XML DOM with extremely
verbose referencing like: -

xmlDoc.getElementsByTagName("compname")[0].childNodes[0].nodeValue;

To get around that I went looking for a DOM walker that would deliver a
Javascript-object version of the XML and found this site
http://goessner.net/download/prj/jsonxml/ which is about the best
XML-to-JSON solution I could locate. Does anyone have a better example that
still uses the browser to parse the XML?

Here's a little potential use example: -

<script type="text/javascript" src="file://c:/xml2json.js"></script>
<script type="text/javascript">
text2='<?xml version=\"1.0\" encoding=\"utf-8\"?><BLAH
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns=\"http://tempuri.org/\">  <FirstName>Fred</FirstName>
<LastName>Nurks</LastName></BLAH>';

// Or use whatever TAG-soup comes down the line from Ajax and your server

var json;
if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(text2,"text/xml");
  }
else // Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(text2);
  }
json = xml2json(xmlDoc," ");
alert(json);
eval("var obj1 = " + json);
</script>

We found it useful with JSON callbacks when overcoming the browser's
cross-domain restrictions. You'll also find this useful if your application
supplier has you accessing their "cloud" to performance-poor servers in
America and you want field-level validation/lookup direct to your local
servers/data.

> PS. Good luck with jQuery and IE8!

Actually, I just tried you ironically titled "keepmeuptodate" site with IE8
and, as expected, it doesn't work. Don't worry, just tell your customers
that it's jQuery's fault and nothing to do with you. I'm sure one of the
thousand or so contributors to the source will get around to fixing it
within SLA, eventually, until the next time :-(

Regards Richard Maher

PS. Did I happen to mention that with Tier3 you can also send JSON down the
line? (In addition to XML, Binary, Comma-Delimited, Size-Delimited, and blob
formatted data)

Did I also mention that server-affinity could be maintained across multiple
message exchanges on a case by case basis, or that the server can return
multiple message responses (eg: result-set) as and when they are created
rather than delaying the transmission until they can all be packaged up in
some monolithic XML-tag fest? Can you see the parallelism opportunities
between client presentation and server manufacture?





More information about the Info-vax mailing list