Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] XOM 1.0 alpha 1 is here

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Bradley S. Huffman" <hip AT cs.okstate.edu>
  • To: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] XOM 1.0 alpha 1 is here
  • Date: Wed, 09 Jun 2004 16:04:00 -0500

Elliotte Rusty Harold writes:

> At 10:20 AM -0500 6/9/04, Bradley S. Huffman wrote:
>
> >But is does change :-) Here's another use case, adding a base attribute to
> >the root element in file://home/hip/text_xom/test.xml
> >
> ><root xml:base="www.acme.org"><foo><bah/></foo></root>
> >
> >Document
> >--------
> >root base uri=file:/home/hip/test-xom/www.acme.org
> >foo base uri=file:/home/hip/test-xom/www.acme.org
> >bah base uri=file:/home/hip/test-xom/www.acme.org
>
> I'm sorry. I can't follow this. You're doing several weird things here:
>
> 1. www.acme.org is a relative URL that just happens to look like a
> host name. Did you mean to say http://www.acme.org? In which case
> you'd get very different results.

Actual no. The point was I create a element, attach it to a document,
remove it, and attach to another document and now getBaseURI() returns
something different then what I think most users would expect.

> 3. I don't know what you mean by far base uri below. :-(

Here's the code

import java.io.IOException;
import nu.xom.*;

public class TestBaseURI {

public static void main(String[] args) {

Builder builder0 = new Builder();
Builder builder1 = new Builder();
try {
Document doc0 = builder0.build("test.xml");
Element root0 = doc0.getRootElement();

System.out.println("\n");
System.out.println("Document");
System.out.println("--------");
printBaseURI(root0);

System.out.println("\n");
System.out.println("After creation");
System.out.println("--------------");
Element e1 = new Element("far");
printBaseURI(e1);

System.out.println("\n");
System.out.println("After appended to root");
System.out.println("----------------------");
root0.appendChild(e1);
printBaseURI(e1);

System.out.println("\n");
System.out.println("After removed from root");
System.out.println("-----------------------");
root0.removeChild(e1);
printBaseURI(e1);

System.out.println("\n");
System.out.println("Document");
System.out.println("--------");
Document doc1 = builder1.build("test1.xml");
Element root1 = doc1.getRootElement();
root1.appendChild(e1);
printBaseURI(root1);

}
catch (IOException ex) {
System.err.println(ex);
}
catch (ParsingException ex) {
System.err.println(ex);
}
}

public static void printBaseURI(Element el) {
String qname = el.getQualifiedName();
String base = el.getBaseURI();

System.out.println(qname + " base uri=" + base);

Elements elements = el.getChildElements();
for (int i = 0; i < elements.size(); i++) {
printBaseURI(elements.get(i));
}
}
}

Here's test.xml

<root xml:base="http://www.acme.org";><foo><bah/></foo></root>

Here's test1.xml

<bang><boom><ding/></boom></bang>

And here's the output

Document
--------
root base uri=http://www.acme.org
foo base uri=http://www.acme.org
bah base uri=http://www.acme.org


After creation
--------------
far base uri=


After appended to root
----------------------
far base uri=http://www.acme.org


After removed from root
-----------------------
far base uri=file:/home/hip/test-xom/test.xml


Document
--------
bang base uri=file:/home/hip/test-xom/test1.xml
boom base uri=file:/home/hip/test-xom/test1.xml
ding base uri=file:/home/hip/test-xom/test1.xml
far base uri=file:/home/hip/test-xom/test.xml

I think getBaseURI() on element "far" returning
"file:/home/hip/test-xom/test.xml"
after it has been remove from the first document, and retaining it after
append
to the second document is going to be very confusing. More confusing then just
internal clearing actualBaseURI on detachment like in 1.0d25.

Brad




Archive powered by MHonArc 2.6.24.

Top of Page