Any way to get node list by giving tagnames without prefixes

E

eva.mukhija

I need to parse various XMLs in my application. It has a generic
template structure but the prefixes with the same tagname may be
inconsistent... so I cannot give prefix in
getElementsByTagName(<tagname>).. (Am using DOM parser).. I've tried
getElementsByTagName("*",<tagname>) but that too didn't work... is
there any way I can fetch the nodelist
Thanks in advance
 
E

eva.mukhija

Sorry for typo .. the second method refers
getElementsByTagNameNS("*",<tagname>)
 
M

Martin Honnen

Sorry for typo .. the second method refers
getElementsByTagNameNS("*",<tagname>)

The prefix does not matter, the namespace URI is what matters, and the
local name, see
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document>
so all you need to know is the namespace URI of the elements you are
looking for (e.g. http://www.w3.org/1999/xhtml for XHTML elements) and
the local name (e.g. p for paragraph elements) then
document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "p")
will give you all XHTML <p> elements, whether they are written as
<p xmlns="http://www.w3.org/1999/xhtml">
or
<pf1:p xmlns:pf1="http://www.w3.org/1999/xhtml">
in the markup does not matter.
 
E

eva.mukhija

Thanks Martin.. but i do not know the namespace uri in advance. So I
tried with the special value "*" to fetch nodes with name p belonging
to any uri as said in the documentation. But that too didn't work..:( ..
 
M

Martin Honnen

but i do not know the namespace uri in advance. So I
tried with the special value "*" to fetch nodes with name p belonging
to any uri as said in the documentation. But that too didn't work..:( ..

Please provide a short sample XML that you are trying to parse, and then
tell us details about which DOM API/parser and which programming
language you use to do that.
Post the relevant snippet of code that tries to access the elements and
tell us exactly what happens, "didn't work" is not specific enough, did
you get a node list with a length of 0, or did you get any error, which
error exactly?
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,843
Latest member
WizcraftEntertainmentAgen

Latest Threads

Top