XML help.

A

Alain-Serge

Hello,
I'm trying to create a XML document from a string comming from a C++
program but I got an exception saying:

org.xml.sax.SAXParseException: Element type "DataFromWebServer" is not
declared


Here "DataFromWebServer" is the name of document root node. Here is
the code:

char cbuf[] = new char[2000];

//Get the data from the socket.
m_inputStream.read(cbuf);
String strdata = new String(cbuf);

//Qt Bug fix: Clean up the strdata.
String strFinalData = strdata.trim();
System.out.println(strFinalData);//For debug

InputSource in = new InputSource ((InputStream) new
ByteArrayInputStream (strFinalData.getBytes()));
XmlDocument xmlDocument =
XmlDocument.createXmlDocument(in, true);


///////////Here is what I got from
System.out.println(strFinalData)///////////

<?xml version = '1.0' encoding = 'UTF-8'?>
<DataFromWebServer>
<AddresseNode>
<Addresse>6</Addresse>
</AddresseNode>
<DatatypeNode>
<Datatype>25</Datatype>
</DatatypeNode>
<DataNode>
<data>6</data>
</DataNode>
</DataFromWebServer>


///////////Here is complete error message////////////////////////////

org.xml.sax.SAXParseException: Element type "DataFromWebServer" is not
declared.
at org.apache.crimson.parser.Parser2.error(Parser2.java:3354)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1502)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.apache.crimson.tree.XmlDocument.createXmlDocument(XmlDocument.java:315)
at COrusSocketThread.run(COrusSocketThread.java:137)
at java.lang.Thread.run(Thread.java:534)







Thanks for your help
Alain-Serge
 
K

Keith M. Corbett

Alain-Serge said:
XmlDocument xmlDocument =
XmlDocument.createXmlDocument(in, true);

The second argument to createXmlDocument specifies whether to validate the
input stream XML.
org.xml.sax.SAXParseException: Element type "DataFromWebServer" is not
declared.

This message means the DataFromWebServer element is not declared in the DTD.
<?xml version = '1.0' encoding = 'UTF-8'?>
<DataFromWebServer>
<AddresseNode>
<Addresse>6</Addresse>
</AddresseNode>
<DatatypeNode>
<Datatype>25</Datatype>
</DatatypeNode>
<DataNode>
<data>6</data>
</DataNode>
</DataFromWebServer>

This XML appears to be well-formed, but not valid. In particular, it does
not contain a !DOCTYPE declaration and DTD which is required for validation.

(In theory, this single entity could be validated, given some
system-dependent means (such as a catalog) for mapping a document type to
DTD. But this is probably not relevant to your situation.)

You can either turn off validation (easy) or add a !DOCTYPE declaration with
a DTD (not hard).

/kmc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top