Closed
Bug 287409
Opened 20 years ago
Closed 20 years ago
loading xml documents from file input stream using nsIDOMParser::parseFromStream fails
Categories
(Core :: XML, defect, P2)
Core
XML
Tracking
()
VERIFIED
FIXED
mozilla1.8beta2
People
(Reporter: asqueella, Assigned: bzbarsky)
References
Details
(Keywords: testcase)
Attachments
(3 files)
1.00 KB,
application/vnd.mozilla.xul+xml
|
Details | |
1.27 KB,
text/html
|
Details | |
3.86 KB,
patch
|
darin.moz
:
review+
jst
:
superreview+
|
Details | Diff | Splinter Review |
Loading XML documents using nsIDOMParser from file input stream fails. The error
message is as follows:
XML Parsing Error: no element found
Location: [...]/test.xul
Line Number: 1, Column: 1
To reproduce, create a simple XML file named test.xml in your profile and open
the attached testcase. The testcase is a XUL file with this script:
----
// get profile directory
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile);
file.append("test.xml");
var fileInputStream =
Components.classes["@mozilla.org/network/file-input-stream;1"].
createInstance(Components.interfaces.nsIFileInputStream);
fileInputStream.init(file, 1, 0, 0);
var domParser = new DOMParser();
var doc = domParser.parseFromStream(fileInputStream, "UTF-8",
fileInputStream.available(), "text/xml");
if(doc.firstChild.firstChild)
alert(doc.firstChild.firstChild.nodeValue);
----
As far as I can see, this happens because nsDOMParser::ParseFromStream() relies
on nsParser to parse the stream passed to it, and nsParser makes use of stream's
ReadSegments() method, that is not implemented for filestreams.
The strange message is because in nsDOMParser::ParseFromStream() the return
value of nsParser::OnDataAvailable() (which is the one that fails) is ignored.
Therefore, nsDOMParser thinks everything was parsed correctly, but the tree is
empty.
The workaround is to read the file into a string and call parseFromString.
Reporter | ||
Comment 1•20 years ago
|
||
Reporter | ||
Comment 2•20 years ago
|
||
oops. You first need to save the testcase to your disk.
Comment 3•20 years ago
|
||
Shaver, this sounds similar to what you ran into, no?
Comment 4•20 years ago
|
||
the code at
http://robert.accettura.com/archives/2004/12/24/reporter-status-update/ probably
fails due to the same issue, only that it's JAR code that doesn't implement
readsegments
(http://lxr.mozilla.org/seamonkey/source/modules/libjar/nsJARChannel.cpp#174)
Comment 5•20 years ago
|
||
bz attempted to help me out a few weeks ago with the attached code.
{As I recall}
Seems to fail on windows, and work on linux.
Comment 6•20 years ago
|
||
Is this a regression? We switched to ReadSegments in bug 197114, more than a
year ago.
Comment 7•20 years ago
|
||
(In reply to comment #6)
> Is this a regression? We switched to ReadSegments in bug 197114, more than a
> year ago.
Isn't the issue here in
http://lxr.mozilla.org/seamonkey/source/parser/htmlparser/src/nsParser.cpp#2605,
unrelated to the external entity references from that bug?
Assignee | ||
Comment 8•20 years ago
|
||
OK. So the reason that loading data from file:// currently works at all is that
nsFileChannel::AsyncOpen wraps the raw file stream up in async stream (using an
input transport), and that implements ReadSegments (it's just an nsPipe).
The DOMParser should probably wrap a buffered stream around the stream it's given.
That said, is it worth making our file streams buffered (eg via mmap() or
something)?
Comment 9•20 years ago
|
||
bz: is this what was busting that buildconfig code?
If so, having this fixed somewhat soon would be very welcome, as I'd like to be
capturing buildconfig when reporter gets rolled out.
Comment 10•20 years ago
|
||
> That said, is it worth making our file streams buffered (eg via mmap() or
> something)?
A nsIInputStream implementation is not required to implement readSegments.
Fixing nsFileInputStream as you suggest is not a solution to the real problem.
The DOM parser should deal with lack of a readSegments implementation. It is
fairly easy to write code that checks to see if readSegments is supported (just
implement a writer callback that consumes no data and have it set a boolean flag
so you can tell that it was tickled).
Comment 11•20 years ago
|
||
BTW, I regret that nsIInputStream was frozen without an isBuffered method to
avoid messy readSegments checking code such as what I suggested above.
Assignee | ||
Comment 12•20 years ago
|
||
> is this what was busting that buildconfig code?
Almost certainly.
> A nsIInputStream implementation is not required to implement readSegments.
I realize that. The real question is whether there would be any sort of
efficiency win... I guess there wouldn't be if we usually wrap them up anyway...
> The DOM parser should deal with lack of a readSegments implementation.
One question is whether the DOMParser should deal or the nsParser should
deal.... The latter is what's really assuming all streams passed to
OnDataAvailable have a ReadSegments that works. That's not part of the
nsIStreamListener interface definition as far as I can tell, so perhaps it
shouldn't be assuming that?
Assignee | ||
Comment 13•20 years ago
|
||
Fix DOMParser to use the new API darin added in bug 287750.
I decided it wasn't worth passing in knowledge about the string and byte
stream; just testing whether the stream is buffered is fast enough.
Attachment #178650 -
Flags: superreview?(jst)
Attachment #178650 -
Flags: review?(darin)
Comment 14•20 years ago
|
||
Comment on attachment 178650 [details] [diff] [review]
Fix
sr=jst
Attachment #178650 -
Flags: superreview?(jst) → superreview+
Comment 15•20 years ago
|
||
Comment on attachment 178650 [details] [diff] [review]
Fix
nit: s/COMPtr/nsCOMPtr/ in the comment
r=darin
Attachment #178650 -
Flags: review?(darin) → review+
Assignee | ||
Updated•20 years ago
|
Assignee: xml → bzbarsky
OS: Windows XP → All
Priority: -- → P2
Hardware: PC → All
Target Milestone: --- → mozilla1.8beta2
Assignee | ||
Comment 16•20 years ago
|
||
Fixed.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 17•20 years ago
|
||
verified using 20050401 win Firefox build, thanks!
Status: RESOLVED → VERIFIED
Comment 18•20 years ago
|
||
*** Bug 296918 has been marked as a duplicate of this bug. ***
You need to log in
before you can comment on or make changes to this bug.
Description
•