Hi Thomas

> I am processing a Schema document, and the default namespace is vanishing:

Thanks for spotting that. During some spring cleaning and optimisation I'd
accidentally broken that (this used to work). I've fixed it now and checked
the changes into CVS. The daily build has these patches so this should now
work fine.

I've used your example document as a JUnit test case to ensure that this
doesn't happen again.

Whilst I was there I added a normalize() method to Branch with the same
semantics as the one in the DOM API to merge adjacent Text nodes and remove
empty Text nodes.

Using this normalize() method means that the TestRoundTrip JUnit test case
now works properly roundtripping a document from dom4j to SAX to DOM to text
to dom4j again. This JUnit test harness actually highlighted a few similar
issues with default namespaces in the DOMReader also which are all now
fixed.

Now we have the TestRoundTrip JUnit test harness I'm quite confident that we
can roundtrip from text <-> dom4j <-> SAX <-> DOM correctly. Though if
anyone can find an XML document that doesn't succesfully roundtrip, please
submit it and we'll fix it and add the document to the unit tests.

James


> In:
> ====
> <schema
>    xmlns='http://www.w3.org/2000/10/XMLSchema'
>    targetNamespace='http://www.w3.org/namespace/'
>    xmlns:t='http://www.w3.org/namespace/'>
>
>   <element name='ex1'>
>    <complexType>
>     <sequence>
>      <element ref='t:x'/>
>     </sequence>
>    </complexType>
>   </element>
>
>   <element name='x'>
>    <complexType mixed='true'>
>    </complexType>
>   </element>
> </schema>
>
> ====
>
>
>
> Out:
> ====
> <?xml version="1.0" encoding="UTF-8"?>
>
> <schema xmlns:t="http://www.w3.org/namespace/";
> targetNamespace="http://www.w3.org/namespace/";>
>    <element name="ex1">
>      <complexType>
>        <sequence>
>          <element ref="t:x"/>
>        </sequence>
>      </complexType>
>    </element>
>    <element name="x">
>      <complexType mixed="true"></complexType>
>    </element>
> </schema>
> ====
>
> Code:
> ====
> package test;
>
> import java.io.*;
> import org.dom4j.io.*;
> import org.dom4j.*;
> import org.dom4j.tree.*;
>
> class ParseTest {
>      static public void main (String args[]) {
> try {
>     if (args.length == 0) {
> System.out.println ("Error: must specify XML file.");
>     }
>     else {
> SAXReader reader = new SAXReader (false);    // No validation.
> Document doc = reader.read (args[0]);
> XMLWriter writer = new XMLWriter(new BufferedOutputStream (new
> FileOutputStream ("ParseTest.out")), OutputFormat.createPrettyPrint());
> writer.write (doc);
> writer.flush();
> // System.out.println (doc.asXML());
>     }
> }
> catch (Exception e) {
>     System.out.println ("Exception: " + e.getMessage());
> }
>      }
> }
> ====
>
> Note that the following has vanished:
>    xmlns='http://www.w3.org/2000/10/XMLSchema'
>
> Am I doing something wrong here? Do I have to explicitly set the default
> namespace, and if so, how?
>
> Thanks,
> Thomas.
>
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dom4j-user
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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

Reply via email to