Hi all,

 

I am getting the “Invalid document structure” error during parsing of an XML file. The scenario is as follows –

 

[1] Platform: Redhat Linux 9.0 and Windows 32-bit

 

[2] Non multi – threaded

 

[3] I am passing an instance of  StdInInputSource class as an argument to the XercesDomParser::parse() method.

 

[4] My test program is being invoked in this way :  cat sim.xml | ./test ( type sim.xml | test on win 32)

 

[5] When I run my program with the same xml file (invoked as ./test sim.xml ) directly, it gives the desired output. Here I have passed an instance of the LocalFileInputSource class as the argument to XercesDomParser::parse() method.

 

What can be the possible cause of this message?

 

Here is the snip of code that I am talking about.

<snip>

Void XMLParser :: parse( void )

    char            whoami[] = "XMLParser::parse";

    XMLCh           *x_file_name = NULL;

 

    // [0]

    XMLPlatformUtils::Initialize();

 

    // [1]

    m_parser = new XercesDOMParser();

    NULLCHECK(m_parser, whoami, "Failed to create XercesDOMParser instance", XML_PARSER_NOMEM);

 

    // [2]

    m_parser->setDoNamespaces(true);

    m_parser->setValidationScheme(XercesDOMParser::Val_Always);

    m_parser->setDoSchema(true);

    m_parser->setCreateEntityReferenceNodes(false);

    m_parser->setCreateCommentNodes(false);

    m_parser->setIncludeIgnorableWhitespace(false);

 

    m_ehandler = (ErrorHandler *)new HandlerBase();

    if (NULL != m_ehandler) {

        m_parser->setErrorHandler(m_ehandler);

    }

 

    // create input source.

    if (m_readFromStdin == true) {

        m_inputSource = new StdInInputSource();

        NULLCHECK(m_inputSource, whoami, "StdInInputSource failed", XML_PARSER_NOMEM);

    } else {

        x_file_name = XMLString::transcode(m_xmlFile.c_str());

        NULLCHECK(x_file_name, whoami, "XMLString::transcode failed", XML_PARSER_FAILED);

        m_inputSource = new LocalFileInputSource((const XMLCh *)x_file_name);

        NULLCHECK(m_inputSource, whoami, "LocalFileInputSource failed", XML_PARSER_NOMEM);

    }

 

    // [3]

    try {

        m_parser->parse((const InputSource &)*m_inputSource);

        //        m_parser->parse((const char *)m_xmlFile.c_str());

    } catch (const XMLException &x) {

        handleXMLException(x);

    } catch (const DOMException &d) {

        handleDOMException(d);

    } catch (const SAXParseException &sp) {

        handleSAXParseException(sp);

    } catch (const SAXException &s) {

        handleSAXException(s);

    }

 

    if (m_parser->getErrorCount() != 0) {

        printf("Errors encountered during parsing file %s\n", m_xmlFile.c_str());

        return XML_PARSER_FAILED;

    } 

</snip>

 

I also tried peeping at the contents that come to the test program from the StdInInputSource. The input that I get from StdInInputSource is exactly similar to what is present in the file. Here is the code to see what comes from the StdInInputSource.

 

<snip>

    // check if input stream is correct

    if (m_readFromStdin == true) {

        bin_in_stream = m_inputSource->makeStream();

        if (NULL == bin_in_stream) {

            printf("bin_in_stream == NULL\n");

            return XML_PARSER_FAILED;

        }

        memset(inbuf, 0, 5000);

        bin_in_stream->readBytes((XMLByte *const)inbuf, 4999);

        printf("%s\n", inbuf);

    }

</snip>

 

Thanks,

Aditya Kulkarni

Reply via email to