Hi All,
While parsing the XSD, I am using the XML_String::transcode function . But this function is not working properly for some UTf-8 chars.

I have a node like
<xsd:attribute name="str00Aٰ" type="xsd:string"/>
This is equivalent to <xsd:attribute name="str00A\xd9\xb0" type="xsd:string"/> when we look in some hex editor.

While transcoding the value of attribute name, I am always getting empty string instead of getting "str00Aٰ" (actual sequence is like "str00A\xd9\xb0")
This is for linux and in case of freebsd my application hangs.

I have attached the sample code , XSD under parsing and the sample output of my program.

Can anyone let me know what's the exact problem in my code or schema or this is a bug in Xerces.
I am using xerces-2.7.0

Thanks in advance.

Thanks.
Regards,
Umesh



#include <xercesc/util/PlatformUtils.hpp>

#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMWriter.hpp>

#include <xercesc/framework/StdOutFormatTarget.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLUni.hpp>

#include "DOMTreeErrorReporter.hpp"
#include "DOMPrintFilter.hpp"
#include "DOMPrintErrorHandler.hpp"
#include <xercesc/util/OutOfMemoryException.hpp>

#include <string.h>
#include <stdlib.h>

// ---------------------------------------------------------------------------
//  Local data
//
//  gXmlFile
//      The path to the file to parser. Set via command line.
//
//  gDoNamespaces
//      Indicates whether namespace processing should be done.
//
//  gDoSchema
//      Indicates whether schema processing should be done.
//
//  gSchemaFullChecking
//      Indicates whether full schema constraint checking should be done.
//
//  gDoCreate
//      Indicates whether entity reference nodes needs to be created or not
//      Defaults to false
//
//  gOutputEncoding
//      The encoding we are to output in. If not set on the command line,
//      then it is defaults to the encoding of the input XML file.
//
//  gSplitCdataSections
//      Indicates whether split-cdata-sections is to be enabled or not.
//
//  gDiscardDefaultContent
//      Indicates whether default content is discarded or not.
//
//  gUseFilter
//      Indicates if user wants to plug in the DOMPrintFilter.
//
//  gValScheme
//      Indicates what validation scheme to use. It defaults to 'auto', but
//      can be set via the -v= command.
//
// ---------------------------------------------------------------------------
static char*                    gXmlFile               = 0;
static bool                     gDoNamespaces          = false;
static bool                     gDoSchema              = false;
static bool                     gSchemaFullChecking    = false;
static bool                     gDoCreate              = false;

static char*                    goutputfile            = 0;
// options for DOMWriter's features
static XMLCh*                   gOutputEncoding        = 0;

static bool                     gSplitCdataSections    = true;
static bool                     gDiscardDefaultContent = true;
static bool                     gUseFilter             = false;
static bool                     gFormatPrettyPrint     = true;
static bool                     gWriteBOM              = false;

static XercesDOMParser::ValSchemes    gValScheme       = XercesDOMParser::Val_Auto;


void usage()
{
    XERCES_STD_QUALIFIER cout << "\nUsage:\n"
            "DOMPrint <XML file>\n\n" <<  XERCES_STD_QUALIFIER endl;
}

int PrintNodes_i(DOMNode * n)
{
	DOMNode *child;
	int rc = 0;
	if (n == 0)
	{
		return 0;
	}
	if (n->getNodeType() == 1)
	{
		char *name = XMLString::transcode(n->getNodeName());
		printf("--------------------\n");
		printf("Encountered Element: %s\n", name);
		XMLString::release(&name);
		char *namespaceURI = XMLString::transcode(n->getNamespaceURI());
		if (namespaceURI != 0)
		{
			printf("Namespace URI: %s\n", namespaceURI);
		}
		XMLString::release(&namespaceURI);
		char *prefix = XMLString::transcode(n->getPrefix());
		if (prefix != 0)
		{
			printf("Prefix: %s\n", prefix);
		}
		XMLString::release(&prefix);
		char *localName = XMLString::transcode(n->getLocalName());
		if (localName != 0)
		{
			printf("Local name: %s\n", localName);
		}
		XMLString::release(&localName);
		if (n->hasAttributes())
		{
			DOMNamedNodeMap *pAttributes = n->getAttributes();
			int nSize = pAttributes->getLength();
			printf("\n");
			printf("\tAttributes\n");
			printf("\t----------\n");
			for (int i = 0; i < nSize; i++)
			{
				DOMAttr *pAttributeNode = (DOMAttr *) pAttributes->item(i);
				char *name = XMLString::transcode(pAttributeNode->getName());
				printf("\t%s = ", name);
				XMLString::release(&name);
				name = XMLString::transcode(pAttributeNode->getValue());
				printf("\"%s\"\n", name);
				XMLString::release(&name);
			}
			printf("\n");
		}
	}
	for (child = n->getFirstChild(); child != 0; child = child->getNextSibling())
	{
		rc = PrintNodes_i(child);
	}
	return rc;
}

int main(int argC, char* argV[])
{
    int retval = 0;

    try
    {
        XMLPlatformUtils::Initialize();
    }

    catch(const XMLException &toCatch)
    {
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
             << "  Exception message:"
             << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
        return 1;
    }

    // Check command line and extract arguments.
    if (argC < 2)
    {
        usage();
        XMLPlatformUtils::Terminate();
        return 1;
    }

    gXmlFile = argV[1];

    //
    //  Create our parser, then attach an error handler to the parser.
    //  The parser will call back to methods of the ErrorHandler if it
    //  discovers errors during the course of parsing the XML document.
    //
    XercesDOMParser *parser = new XercesDOMParser;
    parser->setValidationScheme(gValScheme);
    parser->setDoNamespaces(gDoNamespaces);
    parser->setDoSchema(gDoSchema);
    parser->setValidationSchemaFullChecking(gSchemaFullChecking);
    parser->setCreateEntityReferenceNodes(gDoCreate);

    DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
    parser->setErrorHandler(errReporter);

    //
    //  Parse the XML file, catching any XML exceptions that might propogate
    //  out of it.
    //
    bool errorsOccured = false;
    try
    {
        parser->parse(gXmlFile);
    }
    catch (const OutOfMemoryException&)
    {
        XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
        errorsOccured = true;
    }
    catch (const XMLException& e)
    {
        XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n   Message: "
             << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
        errorsOccured = true;
    }

    catch (const DOMException& e)
    {
        const unsigned int maxChars = 2047;
        XMLCh errText[maxChars + 1];

        XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << gXmlFile << "'\n"
             << "DOMException code is:  " << e.code << XERCES_STD_QUALIFIER endl;

        if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
             XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;

        errorsOccured = true;
    }

    catch (...)
    {
        XERCES_STD_QUALIFIER cerr << "An error occurred during parsing\n " << XERCES_STD_QUALIFIER endl;
        errorsOccured = true;
    }

    // If the parse was successful, output the document data from the DOM tree
    if (!errorsOccured && !errReporter->getSawErrors())
    {
        DOMDocument *doc = parser->getDocument();
	PrintNodes_i(doc);
    }
    else
        retval = 4;

    //
    //  Clean up the error handler. The parser does not adopt handlers
    //  since they could be many objects or one object installed for multiple
    //  handlers.
    //
    delete errReporter;

    //
    //  Delete the parser itself.  Must be done prior to calling Terminate, below.
    //
    delete parser;

    // And call the termination method
    XMLPlatformUtils::Terminate();

    XMLString::release(&gOutputEncoding);

    return retval;
}

<?xml version="1.0" encoding="UTF-8"?>
<!--
Ident: @(#)AD_name00110m2.xsd
   generated from: @(#)AD_name00110m.jmpp	1.3 02/11/14

-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"; targetNamespace="AttrDecl/name">

    <xsd:element name="root">
        <xsd:complexType>
            <xsd:attribute name="str00AÙ°" type="xsd:string"/>
            <xsd:attribute name="str01Aۖ" type="xsd:string"/>
            <xsd:attribute name="str11-ۙ" type="xsd:string"/>
            <xsd:attribute name="str21ۜ" type="xsd:string"/>
            <xsd:attribute name="str02A۝" type="xsd:string"/>
            <xsd:attribute name="str12-۞" type="xsd:string"/>
            <xsd:attribute name="str22۟" type="xsd:string"/>
            <xsd:attribute name="str03AÛ " type="xsd:string"/>
            <xsd:attribute name="str13-Û¢" type="xsd:string"/>
            <xsd:attribute name="str23Û¤" type="xsd:string"/>
            <xsd:attribute name="str04AÛ§" type="xsd:string"/>
            <xsd:attribute name="str14-Û§" type="xsd:string"/>
            <xsd:attribute name="str24Û¨" type="xsd:string"/>
            <xsd:attribute name="str05AÛª" type="xsd:string"/>
            <xsd:attribute name="str15-Û«" type="xsd:string"/>
            <xsd:attribute name="str25Û­" type="xsd:string"/>
            <xsd:attribute name="str06Aँ" type="xsd:string"/>
            <xsd:attribute name="str16-ं" type="xsd:string"/>
            <xsd:attribute name="str26ः" type="xsd:string"/>
            <xsd:attribute name="str07A़" type="xsd:string"/>
            <xsd:attribute name="str08Aा" type="xsd:string"/>
            <xsd:attribute name="str18-ॅ" type="xsd:string"/>
            <xsd:attribute name="str28ौ" type="xsd:string"/>
            <xsd:attribute name="str09A्" type="xsd:string"/>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>
--------------------
Encountered Element: xsd:schema

        Attributes
        ----------
        targetNamespace = "AttrDecl/name"
        xmlns:xsd = "http://www.w3.org/2001/XMLSchema";

--------------------
Encountered Element: xsd:element

        Attributes
        ----------
        name = "root"

--------------------
Encountered Element: xsd:complexType
--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

--------------------
Encountered Element: xsd:attribute

        Attributes
        ----------
        name = ""
        type = "xsd:string"

Reply via email to