473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

libxml2dom - parsing maligned html

Hi...

I'm using quick test with libxml2dom

===============
import libxml2dom

aa=libxml2dom.parseString(foo)
ff=libxml2dom.toString(aa)

print ff
===============

----------------------------------
when i start, foo is:
<html>
<body>
</body>
</html>

<html>
<body>
..
..
..
</body>
</html>
-------------------------------
when i print ff it's:
<html>
<body>
</body>
</html>
-------------------------------

so it's as if the parseString only reads the initial "html" tree. i've
reviewed as much as i can find regarding libxml2dom to try to figure out how
i can get it to read/parse/handle both html trees/nodes.

i know, the html is maligned/screwed-up, but i can't seem to find any app
(tidy/beautifulsoup) that can "know" which one of the html trees to throw
out/remove!!

technically, both html trees are valid, it's just that they both shouldn't
be in the file!!!

thoughts/comments appreciated

thanks
Aug 26 '08 #1
2 1661
On 26 Aug, 17:28, "bruce" <bedoug...@earthlink.netwrote:
so it's as if the parseString only reads the initial "html" tree. i've
reviewed as much as i can find regarding libxml2dom to try to figure out how
i can get it to read/parse/handle both html trees/nodes.
Maybe there's some possibility to have libxml2 read directly from a
file descriptor and to stop after parsing the first document, leaving
the descriptor open; currently, this isn't supported by libxml2dom,
however. Another possibility is to feed text to libxml2 until it can
return a well-formed document, which I do as part of the
libxml2dom.xmpp module, but I don't really support this feature in the
public API.

Again, improvements to libxml2dom may happen if I find the time to do
them.

Paul
Aug 26 '08 #2
bruce wrote:
I'm using quick test with libxml2dom

===============
import libxml2dom

aa=libxml2dom.parseString(foo)
ff=libxml2dom.toString(aa)

print ff
===============

----------------------------------
when i start, foo is:
<html>
<body>
</body>
</html>

<html>
<body>
.
.
.
</body>
</html>
-------------------------------
when i print ff it's:
<html>
<body>
</body>
</html>
-------------------------------

so it's as if the parseString only reads the initial "html" tree. i've
reviewed as much as i can find regarding libxml2dom to try to figure out how
i can get it to read/parse/handle both html trees/nodes.

i know, the html is maligned/screwed-up, but i can't seem to find any app
(tidy/beautifulsoup) that can "know" which one of the html trees to throw
out/remove!!

technically, both html trees are valid, it's just that they both shouldn't
be in the file!!!
What about splitting the string on "<html" and them parsing each part on its own?

Stefan
Aug 26 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ankit | last post by:
Hi I am using libxml2dom package for DOM support in libxml2. There are some test programs in the package when I try to run that samples it give me following error: Traceback (most recent call...
1
by: ankit | last post by:
Hi, I am working with libxml2dom package for having DOM support with libxml2. There are some test examples are given along with the package but when I try to run that, it gives me following...
2
by: ankit | last post by:
I am using libxml2dom but having problem when parsing. It gives me the following error: File "exlibxml2dom.py", line 4, in ? document = libxml2dom.parse("moc.xml") File...
0
by: bruce | last post by:
hi paul... in playing around with the test python app (see below) i've got a couple of basic questions. i can't seem to find the answers via google, and when i've looked in the libxml2dom stuff...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.