Closed Bug 296918 Opened 20 years ago Closed 20 years ago

DOMParser.parseFromStream fails in some cases

Categories

(Core :: XML, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 287409

People

(Reporter: surkov, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; ru-RU; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 (ax)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8b) Gecko/20050217

I have local xml file saved in utf-8 encoding, I load it and then parse it.

var file=Components.classes["@mozilla.org/file/local;1"].createInstance()
				.QueryInterface(Components.interfaces.nsILocalFile);
file.initWithPath(url);
var
istream=Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance()
				.QueryInterface(Components.interfaces.nsIFileInputStream);
istream.init(file, 0x04, null, null);

var domparser=new DOMParser();
var doc=domparser.parseFromStream(istream, null, istream.available(), "text/xml");

doc contains 'parseerror' tag. XML parsing error: no element found.


When I parse document from a string then DOMParser returns "right" document:

var
iistream=Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
iistream.init(istream);
var rep=iistream.read(iistream.available());
domparser.parseFromString(rep, "text/xml");


When I load this file by nsIChannel::open() then I see the same behaviour. If I
load my xml file by nsIChannel::open from http location then DOMParser parses
stream correctly.

Reproducible: Always
does it work if you pass the charset to parseFromStream?

More importantly, does this work in trunk builds? If so, this may be a duplicate
of bug 287409 (and the workaround would be to manually wrap a buffered stream
around the input stream)
Yes, looks like duplicate bug 287409.

If I pass charset "utf-8" then behaviour is not changed. Remark: why
parseFromStream() works when I load xml document from http:// protocol?

I'm glad to test examples on mozilla beta2, but when beta2 will be available?
> why parseFromStream() works when I load xml document from http:// protocol?

the stream returned from the http channel's open() method implements
readSegments, so it does not need a wrapped readSegments.

> I'm glad to test examples on mozilla beta2, but when beta2 will be available?

there won't be an mozilla 1.8beta2 with that name. note
http://wiki.mozilla.org/SeaMonkey:Home_Page

*** This bug has been marked as a duplicate of 287409 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.