[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-user
Subject: RE: XmlBeans and Namespace
From: "Radu Preotiuc-Pietro" <radup () bea ! com>
Date: 2008-04-25 0:40:24
Message-ID: BF6B6CA032BA0A429BD924F96765147DBF2F3B () repbex02 ! amer ! bea ! com
[Download RAW message or body]
You are almost there. You have one of two options:
1. Use XmlOptions.setLoadReplaceDocumentElement(new
javax.xml.namespace.QName("http://www.myexample.com", "Root"))
to replace only the root element with one that matches what you have in
your Schema
2. Change the Schema to add elementFormDefault="qualified" so that
<p:Root xmlns:p="http://www.myexample.com">
<p:Element>
<p:SubElement />
</p:Element>
</p:Root>
is valid and your original XmlOptions works.
Radu
> -----Original Message-----
> From: beboner [mailto:beboner@gmail.com]
> Sent: Tuesday, April 15, 2008 7:23 AM
> To: user@xmlbeans.apache.org
> Subject: XmlBeans and Namespace
>
>
> 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 Root@http://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("htt
> p://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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>
Notice: This email message, together with any attachments, may contain information \
of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be \
confidential, proprietary, copyrighted and/or legally privileged, and is intended \
solely for the use of the individual or entity named in this message. If you are not \
the intended recipient, and have received this message in error, please immediately \
return this by email and then delete it.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic