473,804 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

libxml2dom - parsing maligned html

Hi...

I'm using quick test with libxml2dom

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

aa=libxml2dom.p arseString(foo)
ff=libxml2dom.t oString(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 1678
On 26 Aug, 17:28, "bruce" <bedoug...@eart hlink.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.p arseString(foo)
ff=libxml2dom.t oString(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
1072
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 last): File "prettyprint.py", line 7, in ? d = libxml2dom.parse(sys.argv) File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line 472, in parse
1
1917
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 error: Traceback (most recent call last): File "namespaces.py", line 23, in ? document = libxml2dom.parse("test_ns.xml") File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line
2
1603
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 "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line 472, in parse return parseFile(stream_or_string, html) File "/usr/lib/python2.2/site-packages/libxml2dom/__init__.py", line 484, in parseFile
0
382
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 that i downloaded i didn't see answers either... for the list in the "for label in d.xpath" how can i find out the size of the list???? a simple/basic question, but it's driving me up a wall!!!
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9571
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.