Hi,
I try to load a Xml file without namespace with XMLBeans.
I write my XSD and generate all the classes.

My Xsd model contains the following content
<xs:schema
        xmlns="http://www.myexample.com";
        xmlns:xs="http://www.w3.org/2001/XMLSchema";
        targetNamespace="http://www.myexample.com";>
etc...

My XML contains the following content (i have no access to this file) :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<Root>
    <Element>
        <SubElement />
    </Element>
</Root>

My Java file contain the following content :
File xmlFile = new File("file.xml");
// Load the Xml
RootDocument rootDocument = RootDocument.Factory.parse(xmlFile);

I got the following error because my Xml doesnt contains the namespace
The document is not a [EMAIL PROTECTED]://www.myexample.com: 
document element namespace mismatch expected "http://www.myexample.com"; got
"" (?:?)

Ok no problem, i used the XmlOptions object to set up this information

XmlOptions options = new XmlOptions();
// Set the namespace
options.setLoadSubstituteNamespaces(Collections.singletonMap("",
"http://www.myexample.com";));
// Load the Xml
RootDocument rootDocument = RootDocument.Factory.parse(xmlFile, options);

Now the Factory dont crash but when i try to get a child element of my root
element i got a null pointer
rootDocument.getElement() == null because the Xml document is now like that

<p:Root xmlns:p="http://www.myexample.com";>
    <p:Element>
        <p:SubElement />
    </p:Element>
</p:Root>

I have the impression that XMLbeans do not recognize the element with a
namespace.

I tried to use the given option to remove the prefix but dont really work.
The prefix is removed on the rootDocument but still persist on child
element.
options.setSaveSuggestedPrefixes(Collections.singletonMap("http://www.myexample.com";,
""));

Hope you can help me.
I want just to put the namespace to the root element with the given prefix
like that
<p:Root xmlns:p="http://www.myexample.com";>
    <Element>
        <SubElement />
    </Element>
</p:Root>

Thank you 
-- 
View this message in context: 
http://www.nabble.com/XmlBeans-and-Namespace-tp16700839p16700839.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to