Skip to main content

Namespace prefixes used in the XML document

4 replies [Last post]
sdp198
Offline
Joined: 2005-04-06
Points: 0

Is there a way to determine what namespace prefixes were used in the XML document? The QNames returned by JAXBElement.getName() return an empty string when getPrefix() is called. Also classes which are not wrapped in JAXBElements in the tree don't have QNames.

I'm guessing the Unmarshaller would be the only place this is known, but I couldn't see any function to get a list of prefix mappings.

Thanks,

Steve

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09
Points: 0

JAXBElement.getName().getPrefix() can return some value. You should file this as an issue.

Other classes that have @XmlRootElement can't know the actual QName used in the instance. That's by design.

I'm curious. Why do you need to know the prefix used for an element?

sdp198
Offline
Joined: 2005-04-06
Points: 0

The XML documents use more than one schema. One of those defines an element which behaves like a symbolic link. The example document that I've been given uses prefixes with the element names in the symbolic links, so I was planning to check these. When my colleagues stop changing the schemas I'll check to see if there are any element name conflicts - hopefully there won't be any, then I can stop checking the prefixes.

kohsuke
Offline
Joined: 2003-06-09
Points: 0

I'm not sure what you mean by "element which behaves like a symbolic link"

sdp198
Offline
Joined: 2005-04-06
Points: 0

Sorry, I could have explained that better.

The main schema has an element called "Ref" which has an attribute which contains an XPath expression to point to another element. After unmarshalling the document, this XPath has to be resolved as the effect of the Ref element is to copy the element which it points at into the current position. It's used to make the documents tidier and easier to create.

The problem occurs if this XPath includes namespace prefixes in the node names - I should really check them if they've been specified in the document.