retrieving namespace-uri using JAXP (DOM)

Z

_z33

Hi all,
Is it possible to retrieve the namespace uri of an element from an
XML document, by looking at the schema of the document? To illustrate:
I have an XML document by name 'Request.xml'. The structure of the
document is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<sample:appln xmlns:sample="..."
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="... appln-schema.xsd ">
<sample:ITEM> ... </sample:ITEM>
</sample:appln>

My application right now retrieves the element 'ITEM' by searching
for the name 'ITEM' in the appropriate namespace(say,
"blah...blah...one"). However, doing so I have made an assumption that
the element appears in the namespace, say "blah...blah...one", which is
the namespace uri of the root element. However say tomorrow the XML
changes so that another namespace is declared in the document and the
ITEM moves from the previous namespace "blah...blah...one" to say,
"blah...blah...two". Now my parser would fail to retrieve the element.
So how would I build a parser that can find the namespace that the
element "ITEM" is 'supposed' to appear and then search for it in that
namespace? Or is it worth taking the effort?
I thought when you write a java application to parse an XML, certain
basic assumptions are made like the namespace of the elements...etc...
isn't it? Is there any solution to the problem I am facing? Please,
help.
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top