Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] DOMConverter regression

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] DOMConverter regression
  • Date: Fri, 11 Jun 2004 11:42:16 -0700

DOMConverter in 1.0a1 seems to have a regression bug. The snippet below prints the following bogus output:

test.xml:
<moreovernews>
<article code="13563275">
<url>http://c.moreover.com</url>
<headline_text>e-Commerce Operators Present Version 1.0 of the XML Standard</headline_text>
<source>StockAccess</source>
</article>
</moreovernews>


elem=<article code="13563275">
<url>http://c.moreover.com
<headline_text>e-Commerce Operators Present Version 1.0 of the XML Standard
<source>StockAccess
</source></headline_text></url></article>

If you replace the DOMConverter with the one from 1.0d25 it works fine, though (leaving the rest of xom at 1.0a1). It doesn't show up in every case - the main2() case works fine.

BTW, when i once suggested converting a small piece of code from recursive to iterative manner, I said that that only is a good idea if readability/complexity does not suffer. My impression from all the new iterative work is that this is not the case. The code is a lot harder to understand, and not suprisingly, seems buggy. The cost/value ratio is unfavourable: little value at considerable complexity cost. (As an aside, the same holds for the _xyz methods littered all over 1.0a1).

package gov.lbl.dsd.firefish.trash;

import java.io.*;
import nu.xom.*;
import nu.xom.converters.DOMConverter;

public class XomBug {

public static void main(String[] args) throws Exception {
if ("showbug".equals(args[0]))
main1();
else
main2();
}

public static void main1() throws Exception {
Document doc = new Builder().build(new File("test.xml"));

Element elem = doc.getRootElement().getChildElements().get(0);
org.w3c.dom.Element domElem = xom2dom(elem);
elem = DOMConverter.convert(domElem);
System.out.println("elem="+elem.toXML());
}

public static void main2() throws Exception {
Element items = new Element("moreovernews");
Element e2 = new Element("article");
e2.addAttribute(new Attribute("code", "13563275"));
Element e1 = new Element("url");
e1.appendChild("http://c.moreover.com";);
e2.appendChild(e1);
items.appendChild(e2);
Document doc = new Document(items);

Element elem = e2;
org.w3c.dom.Element domElem = xom2dom(elem);
elem = DOMConverter.convert(domElem);
System.out.println("elem="+elem.toXML());
}

public static org.w3c.dom.Document xom2dom(Document doc) {
return DOMConverter.convert(doc, getDOMImplementation());

// BUGFIX: replace DOMConverter-1.0a1 with DOMConverter-1.0d25
// return DOMConverter2.convert(doc, getDOMImplementation());
}

public static org.w3c.dom.Element xom2dom(Element elem) {
elem = new Element(elem); // copy to avoid multiple parents
//if (elem.getParent() != null) elem = new Element(elem);
return xom2dom(new Document(elem)).getDocumentElement();
}

public static org.w3c.dom.DOMImplementation getDOMImplementation() {
org.w3c.dom.DOMImplementation domImpl = null;
if (domImpl == null) {
javax.xml.parsers.DocumentBuilderFactory factory =

javax.xml.parsers.DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
domImpl =
factory.newDocumentBuilder().getDOMImplementation();
} catch
(javax.xml.parsers.ParserConfigurationException e) {
throw new RuntimeException(e);
}
}

return domImpl;
}
}





Archive powered by MHonArc 2.6.24.

Top of Page