Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML parser

Reply
Thread Tools

XML parser

 
 
vc
Guest
Posts: n/a
 
      06-27-2005
Hi,

I'm looking for an XML parser that wouldn't stop if it finds a minor error
in an XML file. I need to parse an HTML file and there are a lot of HTML
pages that, for instance, don't enclose attribute values in quotes.
Or, for instance, most of HTML pages don't have a root tag/element (that
could be "html"). Instead, they have "doctype" tag before and at the same
level with "html" and XML parsers report an error "no root tag found".

I have tried 3-4 SAX parsers, but none of them works

It would be great if you can recommend a C++ or Java (preferably SAX 2.0
compliant) XML parser.


Thank you in advance,

vc



 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      06-27-2005
vc wrote:
> Hi,
>
> I'm looking for an XML parser that wouldn't stop if it finds a minor error
> in an XML file. I need to parse an HTML file and there are a lot of HTML
> pages that, for instance, don't enclose attribute values in quotes.
> Or, for instance, most of HTML pages don't have a root tag/element (that
> could be "html"). Instead, they have "doctype" tag before and at the same
> level with "html" and XML parsers report an error "no root tag found".
>
> I have tried 3-4 SAX parsers, but none of them works
>
> It would be great if you can recommend a C++ or Java (preferably SAX 2.0
> compliant) XML parser.
>
>
> Thank you in advance,
>
> vc
>
>
>


why don't you use an HTML parser ?

try this one :
http://people.apache.org/~andyc/neko/doc/html/
it's a nice toy

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      06-27-2005
vc wrote:

> I'm looking for an XML parser that wouldn't stop if it finds a minor error
> in an XML file. I need to parse an HTML file and there are a lot of HTML
> pages that, for instance, don't enclose attribute values in quotes.


Use tidy -asxhtml to convert it to XHTML. Then use XPath to query into it.

http://tidy.sourceforge.net/

Shell to tidy with system() or _popen() - don't bother to link it.

And note the entire purpose of XML is to be a well-formed data language, not
a forgiving Notepad-oriented markup language. I really doubt you'l find an
XML parser that permits ill-formed input!

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand


 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      06-27-2005
vc wrote:

> Hi,
>
> I'm looking for an XML parser that wouldn't stop if it finds a minor error
> in an XML file.


onsgmls keeps going to the end (or a configurable number of errors).
Part of OpenSP from http://sourceforge.net/projects/openjade/

> I need to parse an HTML file and there are a lot of HTML
> pages that, for instance, don't enclose attribute values in quotes.


But they may be perfectly valid SGML, not XML. SGML permits lots of
abbreviations that are not allowed in XML.

Or they may just be garbage (more likely
You can run them through HTML Tidy to try and make them XHTML.

> Or, for instance, most of HTML pages don't have a root tag/element (that
> could be "html").


That, too, is permitted in some older SGML DTDs for HTML.

> Instead, they have "doctype" tag before and at the same
> level with "html" and XML parsers report an error "no root tag found".


That's a DocType Declaration. It specified the version of HTML being used
(in theory: in practice it's garbage added by editors which don't know
what they are doing and just throw it in to confuse things).

Again, use HTML Tidy to try and make the file into XHTML.
Then validate with:

$ onsgmls -wxml -s /your/path/to/xml.dec filename.xml

If you use Emacs, this can be configured to happen automatically when you
validate a document, and the error lines get coloured and become links to
the location in the document where the error was spotted.

You will need a copy of the XML Declaration (xml.dec). The original at
http://www.w3.org/TR/NOTE-sgml-xml-971215 is starting to suffer from
bitrot and W3C neglect, so I have put a working copy online at
http://xml.silmaril.ie/xml.dec_onsgmls (note this is slightly different
from the original, which is available at http://xml.silmaril.ie/xml.dec_jc)
Just rename it to xml.dec on your machine.

///Peter
--
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"
 
Reply With Quote
 
Nick Kew
Guest
Posts: n/a
 
      06-27-2005
vc wrote:
> Hi,
>
> I'm looking for an XML parser that wouldn't stop if it finds a minor error
> in an XML file. I need to parse an HTML file and there are a lot of HTML
> pages that, for instance, don't enclose attribute values in quotes.
> Or, for instance, most of HTML pages don't have a root tag/element (that
> could be "html"). Instead, they have "doctype" tag before and at the same
> level with "html" and XML parsers report an error "no root tag found".


People have suggested Tidy, nekohtml and onsgmls. I'd suggest the HTML
parser from libxml2 in preference to those for most purposes.

But you dont' necessarily need any such thing. Although XML parsers
are required to stop on encountering a fatal error, many of them can
be set to continue. For example, mod_validator sets Xerces to continue
so it will report all errors in an XML document.

--
Nick Kew
 
Reply With Quote
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      06-28-2005
Nick Kew ((E-Mail Removed)) wrote:
: vc wrote:
: > Hi,
: >
: > I'm looking for an XML parser that wouldn't stop if it finds a minor error
: > in an XML file. I need to parse an HTML file and there are a lot of HTML
: > pages that, for instance, don't enclose attribute values in quotes.
: > Or, for instance, most of HTML pages don't have a root tag/element (that
: > could be "html"). Instead, they have "doctype" tag before and at the same
: > level with "html" and XML parsers report an error "no root tag found".

: People have suggested Tidy, nekohtml and onsgmls. I'd suggest the HTML
: parser from libxml2 in preference to those for most purposes.

: But you dont' necessarily need any such thing. Although XML parsers
: are required to stop on encountering a fatal error, many of them can
: be set to continue. For example, mod_validator sets Xerces to continue
: so it will report all errors in an XML document.

another is

perl

module: HTML:arser


same idea as a SAX parser, but expects html, handles many many things that
are common, and is quite speedy, and comes pre-installed with many perl
distros.


--

This space not for rent.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML::Parser Installation error: XML-Parser-2.34 Sean Perl Misc 3 10-03-2006 01:23 AM
XML::Parser Installation error: XML-Parser-2.34 Sean Perl Misc 0 10-02-2006 06:20 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
XML-Parser to XML-Parser communication (encoding issues?) arne Perl Misc 0 09-13-2005 12:53 PM
XML Parser VS HTML Parser ZOCOR Java 11 10-05-2004 01:58 PM



Advertisments