Skip to main content

IOException: namespace URI of local name not indexed

8 replies [Last post]
jabberw
Offline
Joined: 2006-01-10

Hi
I'm trying to serialyze a simple document:
<?xml version="1.0" encoding="UTF-8"?>

someval

using DOMDocumentSerializer:
///////
DOMDocumentSerializer domFISerializer =
new DOMDocumentSerializer();
final Writer wr = writer;
domFISerializer.setOutputStream(new OutputStream() {
public void write(int b) throws IOException {
wr.write(b);
}
}
);
///////
and receive next exception:

java.io.IOException: namespace URI of local name not indexed: http://schemas.xmlsoap.org/soap/envelope/
at com.sun.xml.fastinfoset.Encoder.encodeLiteralElementQualifiedNameOnThirdBit(Encoder.java:401)
at com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.encodeElement(DOMDocumentSerializer.java:291)
at com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.serializeElement(DOMDocumentSerializer.java:171)
at com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.serialize(DOMDocumentSerializer.java:83)

//////////
As I see in Encoder:399, all namespaces appearing in the msg must be registered in Vocabulary - is it correct? If so - is there any example to it, please?

Very appreciate any help,
sincerely,
Alex.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jabberw
Offline
Joined: 2006-01-10

Continue to previous posting.. I added one more test.. Strange, I'm not sure the problem is in FI, anyway, its really weird: say, I have a Document outDoc. I use a [i]DOMDocumentSerializer [/i]to serialize it (works fine) and then check if it may be deserialized by [i]SAXDocumentParser[/i], which fails on the mentioned exception. But if I convert the Doc into String, parse it back to Doc - it works well. The same in code:
-----------
try { // this attempt fails.
DOMDocumentSerializer domFISerializer =
new DOMDocumentSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
domFISerializer.setOutputStream(baos);
domFISerializer.serialize(outDoc); <-- fires exception
} catch ( Exception ex) {
System.err.println("-------------");
System.err.println("TEST1:");
ex.printStackTrace();
System.err.println("-------------");
}
try { // but this works
System.out.println("DOC:");
// To XML String
String xml = org.apache.axis.utils.XMLUtils.PrettyDocumentToString(outDoc);
System.out.println(xml);
System.out.println("*****");
// Create new Doc on this XML String
javax.xml.parsers.DocumentBuilder db = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xml)));
// Serialize it
ByteArrayOutputStream o3 = new ByteArrayOutputStream();
DOMDocumentSerializer ser = new DOMDocumentSerializer();
ser.setOutputStream(o3);
ser.serialize(doc);
// Deserialize it
ByteArrayInputStream bais = new ByteArrayInputStream(o3.toByteArray());
SAXDocumentParser parser = new SAXDocumentParser();
parser.parse(bais);
} catch ( Exception ex) {
System.err.println("-------------");
System.err.println("TEST2:");
ex.printStackTrace();
System.err.println("-------------");
}

jabberw
Offline
Joined: 2006-01-10

Hi Paul
It seems I was happy too fast :) There is another problem. For this code snippet:

DOMDocumentSerializer domFISerializer =
new DOMDocumentSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
domFISerializer.setOutputStream(baos);
// wroks pretty good
domFISerializer.serialize(outDoc);

ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
SAXDocumentParser parser = new SAXDocumentParser();
parser.parse(bais);

an exception is thrown in last line ( parser.parse(bais) ) :
org.jvnet.fastinfoset.FastInfosetException: Qualified name of EII not in scope
at com.sun.xml.fastinfoset.sax.SAXDocumentParser.processEII(SAXDocumentParser.java:574)
at com.sun.xml.fastinfoset.sax.SAXDocumentParser.processEIIWithNamespaces(SAXDocumentParser.java:951)
at com.sun.xml.fastinfoset.sax.SAXDocumentParser.processDII(SAXDocumentParser.java:415)
at com.sun.xml.fastinfoset.sax.SAXDocumentParser.parse(SAXDocumentParser.java:345)
at com.sun.xml.fastinfoset.sax.SAXDocumentParser.parse(SAXDocumentParser.java:307)

/////////////
Is it some my mistake again?
Great thanx ahead,
sincerely,
Alex.

sandoz
Offline
Joined: 2003-06-20

> Hi Paul
> It seems I was happy too fast :) There is another
> problem. For this code snippet:
>

Not good :-(

> Is it some my mistake again?

I think again it is due to the way the DOMDocumentSerializer works. There is one or more namespace declaration that still needs to be declared on the DOM.

My bet is you have some XML like this:




For the first 'sub' is bound to a namespace declaration and the second is not.

Paul.

jabberw
Offline
Joined: 2006-01-10

Here is the document I tried to test. It seem sthere is no forgotten namespaces this time:
-------------




-----

Sincerely,
Alex

sandoz
Offline
Joined: 2003-06-20

> Here is the document I tried to test. It seem sthere
> is no forgotten namespaces this time:
> -------------
>
>
> > xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelop
> e/" xmlns:Ñ…sd="http://www.w3.org/2001/XMLSchema"
> xmlns:Ñ…si="http://www.w3.org/2001/XMLSchema-instance">
>
>
>
> ing
> soapenv:encodingStyle="http://schemas.xmlsoap.org/soap
> /encoding/" xmlns:ns1="http://ws.vinodtest">
>
> >
>
>

The above example is odd because there are no prefixes for the elements.

Could you:

1) Send me the FI document, and i can find where it is
going wrong and identify the source of the problem in
the serialization; or

2) You run the fi/FastInfoset/bin/saxtosaxevent
and send the output to here. (set FI_HOME env to the
path of the FastInfoset dir).

Paul.

sandoz
Offline
Joined: 2003-06-20

> Hi
> using DOMDocumentSerializer:
> ///////
> DOMDocumentSerializer domFISerializer =
> new DOMDocumentSerializer();
> final Writer wr = writer;
> domFISerializer.setOutputStream(new OutputStream()
> ) {
> public void write(int b) throws IOException
> xception {
> wr.write(b);
> }
> }
> );
> ///////

Not quite sure why you are using a Writer since this is only meant for character streams and not binary (octet) streams. I recommend using a instance of ByteArrayOutputStream.

> and receive next exception:
>
> java.io.IOException: namespace URI of local name not
> indexed: http://schemas.xmlsoap.org/soap/envelope/
> at
> t
> com.sun.xml.fastinfoset.Encoder.encodeLiteralElementQu
> alifiedNameOnThirdBit(Encoder.java:401)
> at
> t
> com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.enco
> deElement(DOMDocumentSerializer.java:291)
> at
> t
> com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.seri
> alizeElement(DOMDocumentSerializer.java:171)
> at
> t
> com.sun.xml.fastinfoset.dom.DOMDocumentSerializer.seri
> alize(DOMDocumentSerializer.java:83)
>
> //////////
> As I see in Encoder:399, all namespaces appearing in
> the msg must be registered in Vocabulary - is it
> correct? If so - is there any example to it, please?
>

I think the problem is that there is no namespace declaration for the URI:

"http://schemas.xmlsoap.org/soap/envelope/".

The DOM serializer is currently a bit dumb and does not declare namespaces. It is necessary for the namespace declarations to already be declared.

On the root element try doing:

element.setAttributeNS(
"http://www.w3.org/2000/xmlns/",
"xmlns",
"http://schemas.xmlsoap.org/soap/envelope/");

To set the default namespace to that of:

"http://schemas.xmlsoap.org/soap/envelope/"

presuming that you are using the default namespace. Otherwise the second parameter will need to be somethineg like:

"xmlns:soap"

or whatever prefix is used.

Hope this solves your problem.

Please let me know if you desparately need the DOM serializer to declare namespaces for you and i will try and do something about it.

Paul.

jabberw
Offline
Joined: 2006-01-10

Hi, Paul
Thanx a lot! This really solves a problem.
Generally, if we are talking about what may be done to make a usage more comfortable - at least the point I faced - FI supplies the [i]com.sun.xml.fastinfoset.sax.SAXDocumentParser[/i] which implements the standard [i]org.xml.sax.XMLReader[/i] but it does not have an standard parser [i]javax.xml.parsers.SAXParser[/i] (at least I didn't find but may be i'm wrong), and in my case that's what I need. As a matter of fact this lack be easily solved - the shortest, but sure, a bit ugly -
///---------------------------
SAXParser parser = null;
XMLReader reader = null;
reader = new com.sun.xml.fastinfoset.sax.SAXDocumentParser(); org.apache.crimson.jaxp.SAXParserFactoryImpl fcim =
new SAXParserFactoryImpl();
parser = fcim.newSAXParser();
java.lang.reflect.Field readerF =
parser.getClass().getDeclaredField("xmlReader");
readerF.setAccessible(true);
readerF.set(parser, reader);
///----------------------------
but of course the ready clean FastParser would look much more healthy and nice :)

Thank you once more,
Alex.

sandoz
Offline
Joined: 2003-06-20

> Hi, Paul
> Thanx a lot! This really solves a problem.

Great!

You are right, there is no JAXP implementation.

This is something that needs further investigation and looks useful to do. One thing that is very important, i think, is such an implementation should also be able to process XML documents as well as fast infoset documents so that no unexpected behavour occurs. Thus the SAXParser.parse method needs to look at the first couple of bytes of an input stream to decide what underlying parser to use.

Paul.