IE 6 and XML DOM

R

RobG

I'm doing some prototyping with XML files in an environment that uses
IE 6 as the default browser. I have no trouble doing what I want with
Firefox, however some users want to use IE 6.

As IE 6 doesn't have getElementsByTagNameNS and getElementsByTagName
doesn't seem to work on XML files with a namespace, I've written a
routine to recurs over child nodes looking for matching tag names.
It's not particularly efficient but it works, a section of the XML
looks like:

<ns1:parcel ...>
<ns1:CoordGeom ...>
<ns1:Line ... />
<ns1:Line ... />
</ns1:CoordGeom>
</Parcel>

I'd like to know if there is a better way to approach this? I'm
thinking of converting the XML DOM to a javascript object and creating
all my own access methods, but that seems a very heavy handed approach
just to keep IE happy.
 
T

Thomas 'PointedEars' Lahn

RobG said:
I'm doing some prototyping with XML files in an environment that uses
IE 6 as the default browser. I have no trouble doing what I want with
Firefox, however some users want to use IE 6.

As IE 6 doesn't have getElementsByTagNameNS and getElementsByTagName
doesn't seem to work on XML files with a namespace, I've written a
routine to recurs over child nodes looking for matching tag names.
It's not particularly efficient but it works, a section of the XML
looks like:

<ns1:parcel ...>
<ns1:CoordGeom ...>
<ns1:Line ... />
<ns1:Line ... />
</ns1:CoordGeom>
</Parcel>

Your XML fragment is not well-formed said:
I'd like to know if there is a better way to approach this?

XPath, of course. For example (tested in IE 6.0.2800.1106):

var lines = xmlDoc.documentElement.selectNodes("//ns1:Line");

/* should display 2 */
window.alert(lines.length);

See also <http://msdn.microsoft.com/en-us/library/ms754523(VS.85).aspx>


PointedEars
 
R

RobG

Your XML fragment is not well-formed, the last tag must be </ns1:parcel>.

My bad, trimmed too much and re-typed in the last tag incorrectly.
XPath, of course.  For example (tested in IE 6.0.2800.1106):

Didn't occur to me to try it - I just assumed that if simple DOM Core
methods weren't available, XPath wouldn't be either. I've been using
XML style sheets as a quick viewer, so I should have just tried it.
  var lines = xmlDoc.documentElement.selectNodes("//ns1:Line");

  /* should display 2 */
  window.alert(lines.length);

See also <http://msdn.microsoft.com/en-us/library/ms754523(VS.85).aspx>

Thanks.
 
T

Thomas 'PointedEars' Lahn

RobG said:
My bad, trimmed too much and re-typed in the last tag incorrectly.

Never mind, it was just an aside.
Didn't occur to me to try it - I just assumed that if simple DOM Core
methods weren't available, XPath wouldn't be either.

Indeed, I also find it illogical of M$ to not provide the simpler
interface, but only the more complex one. Then again, what else is new?
I've been using XML style sheets as a quick viewer, so I should have
just tried it.

In fact, shortly after posting I have found it to be explicitly mentioned
in the documentation for IXMLDocument::getElementsByTagName() :)

,-<http://msdn.microsoft.com/en-us/library/ms762212(VS.85).aspx>
|
| [...]
| Remarks
|
| [...]
| The getElementsByTagName method simulates the matching of the provided
| argument against the result of the tagName property of IXMLDOMElement.
| When executed, it does not recognize or support namespaces. Instead,
| you should use the selectNodes method, which is faster in some cases
^^^^^^^^^^^
| and can support more complex searches.

(You can see your assumption about namespace support confirmed there, too.)

You're welcome.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top