Skip to main content

FastInfosetException: org.w3c.dom.DOMException: NAMESPACE_ERR

1 reply [Last post]
sambhav_chhajed
Offline
Joined: 2008-10-17
Points: 0

Hi,

I have a small java code which does a round trip with fast Infoset. Basically program takes a XML document as input and converts it to Fast Infoset and then reverse way Fast Infoset to XML. I am using DOMDocumentSerializer and DomDocumentParser for the same.

Facing following exception while converting Fast Infoset to XML

org.jvnet.fastinfoset.FastInfosetException: org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.parse(DOMDocumentParser.java:120)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.parse(DOMDocumentParser.java:100)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.parse(DOMDocumentParser.java:95)
at test.fiToDom(test.java:59)
at test.main(test.java:17)
Caused by: org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
at org.apache.xerces.dom.AttrNSImpl.setName(Unknown Source)
at org.apache.xerces.dom.AttrNSImpl.(Unknown Source)
at org.apache.xerces.dom.CoreDocumentImpl.createAttributeNS(Unknown Source)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.createAttribute(DOMDocumentParser.java:1030)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.processAIIs(DOMDocumentParser.java:796)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.processEII(DOMDocumentParser.java:327)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.processDII(DOMDocumentParser.java:164)
at com.sun.xml.fastinfoset.dom.DOMDocumentParser.parse(DOMDocumentParser.java:116)
... 4 more

After debugging seems like some problem with DOMDocumentParser, is it a bug or I am doing something wrong here??

I don’t know how to attach files here; following is my test program and sample XML I’m using

Thanks in Advance.
--Sambhav

test.java

import java.io.*;
import javax.xml.parsers.*;
import org.jvnet.fastinfoset.FastInfosetException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.sun.xml.fastinfoset.dom.*;

public class test {

public static void main(String[] args) {
try {
Document doc = buildDom("test.xml");
System.out.println("----------DOM Created---------------");
byte[] bty = domToFi(doc);
System.out.println("----------DOM TO FI CONVERTED-------");
fiToDom(bty);
System.out.println("----------FI TO DOM CONVERTED-------");
}catch(Throwable oops)
{
System.out.println("Conversion Failed!!!");
oops.printStackTrace();
}
}

private static Document buildDom(String fileName) throws FileNotFoundException,
ParserConfigurationException, SAXException, IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName));

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(bis);

return doc;
}

private static byte[] domToFi(Document doc) throws IOException{
ByteArrayOutputStream fileOut = new ByteArrayOutputStream();

DOMDocumentSerializer s = new DOMDocumentSerializer();
s.setOutputStream(fileOut);
s.serialize(doc);

byte[] bty = fileOut.toByteArray();

return bty;
}

private static Document fiToDom(byte[] bty) throws ParserConfigurationException, FastInfosetException, IOException{

Document doc = null;
BufferedInputStream document = new BufferedInputStream(new ByteArrayInputStream(bty));

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.newDocument();
DOMDocumentParser ddp = new DOMDocumentParser();
ddp.parse(doc, document);

return doc;
}
}

test.xml

<?xml version="1.0" encoding="UTF-8"?>

S03-034257
2003-02-03

Jerry Builder plc

Marsh Lane
Nowhere
NR18 4XX
Norfolk

Eva Brick

Specialist Windows plc

Snowhill Works
Little Snoring
SM2 3NW
Whereshire

2003-02-24T00:00:00

Riverside Rd.
Plot 17, Whitewater Estate
Whetstone
Middlesex

A
2

236WV

wood
soft

finish
primed

fittings
satin

glazing
single

B
3

340TW

hand
RH

wood
hard

finish
stain

fittings
brass

glazing
double

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
oleksiys
Offline
Joined: 2006-01-25
Points: 0

Please set namespace aware for DOM builder factory to true... like:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();

Hope this will help.