You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Mithun <mc...@gmail.com> on 2010/08/13 09:17:14 UTC

SetEncoding issue DOMLSInput as MEMPARSE_ENCODING

Hi,
           I'm looking for a solution of setencoding for parsing a xml file.
Writing a wrapper like module for xerces which will help to parse XML string
comming from the network. So i have used DOMLSinput for setStringdata(); 
           I can parse files with encoding="UTF-8" by default. But when i use a
sample file with encoding='" MEMPARSE_ENCODING "' Im getting segmentation fault.
I have searched and tried some options from "XMLUni" but result is same. 

1) Can you point me out which one have to be set for encode?
2) How I can understand that type on the fly before setting it to be parsed?

XMLFILE:
<?xml version='1.0' encoding='" MEMPARSE_ENCODING "'?>
<!DOCTYPE company [
<!ELEMENT company     (product,category,developedAt)>
<!ELEMENT product     (#PCDATA)>
<!ELEMENT category    (#PCDATA)>
<!ATTLIST category idea CDATA #IMPLIED>
<!ELEMENT developedAt (#PCDATA)>
]>
<company>
    <product>XML4C</product>
    <category idea='great'>XML Parsing Tools</category>
    <developedAt>
      IBM Center for Java Technology, Silicon Valley, Cupertino, CA
    </developedAt>
</company>


code segment:

MemBufInputSource is((XMLByte*)memblock, strlen(memblock), "bufId");
XMLString::transcode(memblock,XMLstr,fSize-1);
impl = DOMImplementationRegistry::getDOMImplementation(gLS);
parser = (impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS,0);
input = ((DOMImplementationLS*)impl)->createLSInput();
input->setStringData(XMLstr);/*********************************************/
//input->setEncoding(XMLUni::fgAnyString); /*we have to set proper encoding by
checking b4 it to be parsed!*/

thanking you
MCM






Re: SetEncoding issue DOMLSInput as MEMPARSE_ENCODING

Posted by David Bertoni <db...@apache.org>.
On 8/13/2010 12:17 AM, Mithun wrote:
> Hi,
>             I'm looking for a solution of setencoding for parsing a xml file.
> Writing a wrapper like module for xerces which will help to parse XML string
> comming from the network. So i have used DOMLSinput for setStringdata();
>             I can parse files with encoding="UTF-8" by default. But when i use a
> sample file with encoding='" MEMPARSE_ENCODING "' Im getting segmentation fault.
> I have searched and tried some options from "XMLUni" but result is same.
This is neither a valid encoding, nor valid syntax for specifying an 
encoding. Still, Xerces-C should not cause a segmentation violation.
Can you provide a minimal program and an input document to reproduce 
this and create a Jira issue?

> 2) How I can understand that type on the fly before setting it to be parsed?
There's no way to determine the encoding of a document for certain. 
There are ways to do statistical analysis of a document to guess its 
encoding, but that analysis can fail.

Dave