XML help.

Discussion in 'XML' started by Alain-Serge, Jul 29, 2004.

  1. Alain-Serge

    Alain-Serge Guest

    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
     
    Alain-Serge, Jul 29, 2004
    #1
    1. Advertising

  2. "Alain-Serge" <> wrote in message
    news:...
    > 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
     
    Keith M. Corbett, Aug 1, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bomb Diggy
    Replies:
    0
    Views:
    447
    Bomb Diggy
    Jul 28, 2004
  2. Tony Prichard
    Replies:
    0
    Views:
    736
    Tony Prichard
    Dec 12, 2003
  3. Mark Van Orman

    embedding xml in xml as non-xml :)

    Mark Van Orman, Sep 14, 2004, in forum: XML
    Replies:
    5
    Views:
    481
    Patrick TJ McPhee
    Sep 15, 2004
  4. Andy
    Replies:
    0
    Views:
    539
  5. Erik Wasser
    Replies:
    5
    Views:
    463
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page