Hello,

I am trying since a few days to read a local xml file in XPCOM c++
into a nsIDOMDocument.

My file contains (utf-8) :
<a><b>sd</b></a>

I wrote the code below (omitting "function return code" verification parts) :

nsILocalFile* xmlFile;
rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID,
                                       nsnull,
                                       NS_GET_IID(nsILocalFile),
                                        (void**)&xmlFile);
rv = xmlFile->InitWithPath(xmFilePath);

nsIInputStream* fin;
rv = NS_NewLocalFileInputStream(&fin, xmlFile);

PRUint32 uiContentLength;
rv = fin->Available(&uiContentLength);

nsCOMPtr<nsIDOMParser> domParser;
domParser = do_CreateInstance( "@mozilla.org/xmlextras/domparser;1", &rv );
rv = domParser->ParseFromStream(fin, "UTF-8", uiContentLength,
"text/xml", xmlDOM);

But when i run my component the last line above causes a firefox crash
because of a memory address violation.

Then i had the idea to read the stream first into a string using the
read method :

char * xmlString = new char[uiContentLength];
fin->Read(xmlString, uiContentLength, &rv);

But while displaying the string, instead of <a><b>sd</b></a>
here is the string displayed : <a><b>sd</b></a>ýýýýÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ

What are the last caracters ...??
Even when i decrease uiContentLength (uiContentLength =
uiContentLength-10 for example) i already have the strange caracters ý
and Ý...

Perhaps this value explains the firefox crash while running the
original code (above) ?

Someone met the same problems whith nsIFileInputStream and could
please help me to resolve it ?

If you have some working code making about what i want, i am also interessed.

Thank you in advance.

_______________________________________________
Mozilla-xpcom mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to