How do you do this if you don't know the prefixes?

Say I get two XML files:

#1

<u:Body>
.
.
.
.
</u:Body>

#2:

<a:Body>
.
.
.
</a:Body>

u and a are mapped to same namespace.

I want to select Body.

How can I do so in a way that is not so dependent on what prefix the
original author of the document used?

Jim


Jim Brain, [EMAIL PROTECTED]
"Researching tomorrow's decisions today."
(319) 369-2070 (work)
SYSTEMS ARCHITECT, ITS, AEGON FINANCIAL PARTNERS

 -----Original Message-----
From:   James Strachan [mailto:[EMAIL PROTECTED]] 
Sent:   Monday, March 04, 2002 8:55 PM
To:     David Hooker; [EMAIL PROTECTED]
Subject:        Re: [dom4j-user] default namespace issue

From: "David Hooker" <[EMAIL PROTECTED]>
> Isn't there a dom4j API call to get the namespace URI's from the XML
> file and bind them into your xpath expression?

Kind of, though a document can redefine prefixes <-> URI mappings throughout
the document, so you need to pick a node and get the namespaces available
there.

By default dom4j with inherit any namespace prefixes -> URIs that are
available in the source node on which XPaths occur. e.g. if you parsed this
document

<foo:root
    xmlns:foo="http://www.foo.com/123";
    xmlns:bar="http://somewhere.com/bar";>
    <bar:one>
        <bar:two>hello!</bar:two>
    </bar:one>
</foo:root>

Then the following XPath expression on the document (or
document.getRootElement()) should work fine...

foo:root/bar:one/bar:two

James


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to