DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6767>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6767

unable to serialize doc without explicit namespace prefixes

           Summary: unable to serialize doc without explicit namespace
                    prefixes
           Product: Xerces2-J
           Version: 2.0.0
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Serialization
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


It would seem there is no way to serialize out an XML Document using namespaces, so 
that it omits the 
default (as defined by it's XML Schema) namespace declaration from all the elements 
and 
attributes. 

What I want to get as a result, is a document looking like this:

<root 
id="blah" xmlns="http://xml.myurl.com/foo"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://xml.myurl.com/foo foo.xsd">
        <elem>Some 
text</elem>
...etc

where root, root's id attribute, and elem are are all implicitly in the 
foo namespace from foo.xsd.

I am creating the document with a DocumentBuilder created like 
so:

DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
factory.setValidating(validation);
factory.setNamespaceAware(true);
factory.setAttribute("http://apache.org/xml/features/validation/schema";, 
new 
Boolean(true));
factory.setAttribute("http://apache.org/xml/features/validation/schema-
full-checking", new 
Boolean(true));
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage";, 
"http://www.w3.org/2001/XMLSchema";);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder 
parser = factory.newDocumentBuilder();

I use the methods Element.setAttributeNS and 
Document.createElementNS to create my document, for example

Element rootElem = 
doc.createElementNS("http://xml.myurl.com/foo";, "foo:root");

The document created 
by the XmlSerializer comes out looking like this:

<foo:taxonomy 
xmlns:foo="http://xml.myurl.com/foo"; foo:id="blah">
    <foo:elem>Some 
text</foo:elem>
etc...

This is assuming I make no attempt to explicitly create the xmlns, 
xmlns:xsi, xsi:schemaLocation attributes on the root. If I also 
create:

rootElem.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance";, 
"xsi:schemaLocation", "http://xml.myurl.com/foo foo.xsd");

xmlns:xsi, and 
xsi:schemaLocation get created properly in the output. However it still creates on the 
root 
element.

xmlns:foo="http://xml.myurl.com/foo";
instead of just 

xmlns="http://xml.myurl.com/foo";

Which I expect is the root of the problem.

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

Reply via email to