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.
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.