Re: Recovering from errors in an XML "stream"
Webb Scales <[email protected]> Tue, 24 Sep 2019 17:29:36 -0400
| Newsgroups | gmane.comp.gnome.lib.xml.general |
|---|---|
| Organization | URSA, Inc. |
| Message-ID | <[email protected]> |
Thanks, Eric -- that's an interesting suggestion. Does this work for you because the '<' character is not permitted in the stream except as the opening of a tag (which makes it very straightforward to locate each tag) and the root tag is not permitted to appear inside the document (or, are you doing a nesting count?)? I'm trying to ensure that my code doesn't have to know too much about XML or maintain too much state (that's what I'm using LibXML2 for! :-) ). Thanks, Webb On 9/24/19 5:14 PM, Eric Eberhard wrote: > > You can easily read the XML using TCP/IP yourself and find the ending > tag, process, read the next document, process, etc. We do that always > (much easier than other ideas). You know the ending tag from the > starting tag and there are issues about blocking and non-blocking > reads. We read one byte blocking and as soon as we get something we > read until the ending tag and pause for processing. Eric > > *From:*xml [mailto:[email protected]] *On Behalf Of *Webb Scales > *Sent:* Monday, September 09, 2019 9:30 PM > *To:* Liam R E Quin <[email protected]>; [email protected] > *Subject:* Re: [xml] Recovering from errors in an XML "stream" > > I'm OK with making small on-the-fly "edits" to the input (such as > removing the initial comment, or removing all comments), but trying to > make my code discern the overall structure (such as picking out the > boundaries between the documents) is starting to step over into > actually parsing it, which defeats the purpose of using LibXML2. > > If the TextReader didn't insist upon reading beyond the root end-tag, > that would enable me to solve my problem, I think. (I don't understand > why it does that.) In the absence of any other options, I'm going to > experiment with the SAX interface and see if that will allow me to > stop the parse at the right spot. > > Anyway, thanks for your replies, Liam. > > > Webb > > > On 9/10/19 12:19 AM, Liam R E Quin wrote: > > On Mon, 2019-09-09 at 22:41 -0400, Webb Scales wrote: > > the > > fact remains that I don't control the text that I'm trying to parse, > > and I still need to parse it, even though it's not "well-formed". > > You may need to write some form of pre-processor that fixes the > > problems. As you say, that may reduce the need for an XML parser. > > I haven't investigated error recovery with libxml, so someone else > > might have better ideas. > > Liam > -- Webb Scales Principal Software Architect 603-673-2306 www.ursasecure.com <https://www.ursasecure.com> [email protected] <mailto:[email protected]> _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] https://mail.gnome.org/mailman/listinfo/xml