473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setDocumentLoca tor in validating parser (xmlproc)

Hi,

it seems that xmlproc, the default Validating parser, in my setup does
not call back to setDocumentLoca tor. Is there anyway to get a locator
in my handler?
Below you find an example and its output.

Regards, Cees

# base imports
from xml.sax.handler import ContentHandler
from xml.sax.handler import EntityResolver
import xml.sax
import xml.sax.sax2ext s

class BaseHandler(Con tentHandler):
def setDocumentLoca tor(self,locato r):
print "setDocumentLoc ator called"
self.d_locator= locator

def startElement(se lf, name, attr):
print "startEleme nt", name
open('e.dtd','w ').write('<!ELE MENT E EMPTY>')
open('e.xml','w ').write(
"""<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE E SYSTEM "e.dtd"><E/>""")

vp = xml.sax.sax2ext s.XMLValParserF actory.make_par ser()
print "vp type", vp.__class__
vph = BaseHandler()
vp.setContentHa ndler(vph)
vp.parse("e.xml ")

np = xml.sax.make_pa rser()
print "np type", np.__class__
nph = BaseHandler()
np.setContentHa ndler(nph)
np.parse("e.xml ")

OUTPUT:
vp type xml.sax.drivers 2.drv_xmlproc.X mlprocDriver
startElement E
np type xml.sax.expatre ader.ExpatParse r
setDocumentLoca tor called
startElement E
Jul 18 '05 #1
2 2392
"Cees Wesseling" <ce**@pcraster. nl> wrote in message
news:6b******** *************** ***@posting.goo gle.com...
it seems that xmlproc, the default Validating parser, in my setup does
not call back to setDocumentLoca tor. Is there anyway to get a locator
in my handler?


It's a known bug with a simple patch -- I don't know why it wasn't fixed in
PyXML 0.8.4.
http://sourceforge.net/tracker/?func...73&atid=106473

I had the same problem a while ago; I ended up doing a monkeypatch to
xml.sax.drivers 2.drv_xmlproc to add the missing call:

import xml.sax.drivers 2.drv_xmlproc

# Override the set_locator method.
def set_locator(sel f, locator):
# Existing code.
self._locator = locator
# ...but also call the ContentHandler.
# drv_xmlproc already implements the Locator interface.
self._cont_hand ler.setDocument Locator(self)

setattr(xml.sax .drivers2.drv_x mlproc.XmlprocD river, "set_locato r",
set_locator)

HTH,

James Kew
http://jameskew.blogspot.com
Jul 18 '05 #2
"James Kew" <ja*******@gmai l.com> wrote in message news:<d1******* ***@news.astoun d.net>...

Thanks James, a perfect patch that works perfect for me.

On a side note, it seems the locator is not standarized. expat gives
positions at the "<"-char of startElement while xmlproc (PyXml) gives
it the ">"-char of startElement.An d both one columnNumber off. A bit
annoying when swapping parsers.

Cees
Jul 18 '05 #3

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

Similar topics

2
2484
by: Benjamin Niemann | last post by:
Hi, does anyone know of a validating SGML parser in python (like xmlproc.xmlval does for XML)? Goal is to validation HTML against the DTD, similar to validator.w3.org, not all SGML obscurities are required. If real SGML validation is no option, I could probably rewrite the HTML to make it XML conformant and feed it into xmlval - but then...
2
1960
by: Magnus Heino | last post by:
Hi. Are there any patterns or other design techniques that could be used when implementing a xml parser that needs to be able to handle different versions of a schema? Let's say that I write a xml parser that can parse xhtml 1.0. Now I want it to be able to handle both xhtml 1.0 and xhtml 1.1. How should I design my application?
16
6296
by: Mike | last post by:
Does anyone know of a minimal/mini/tiny/small xml parser in c? I'm looking for something small that accepts a stream or string, builds a c structure, and then returns an opaque pointer to that structure. There should then be a function to search that structure given the pointer, tag, and an optional attribute. I'm looking initially at only...
4
2553
by: jsonstein | last post by:
I am going nuts trying to find a DTD validation service online... is there any site which offers validation of DTDs online and which does the validation in an authoritative manner? thanks jeffs
0
1297
by: jean-gert nesselbosch | last post by:
hello everybody, does anybody know of standardization efforts concerning the output of w3cSchema/relaxNG-validating parsers ? I use libxml2 for validation-purposes (w3c-Schema and relaxNG) and have the impression that (a) the output in case the xml-document is not valid, is not very verbose (b) the structure of the returned message (in...
3
1361
by: tom | last post by:
Hi folks Is there a piece of software or a wbsite that validates the content inside an XML node? I download an XML feed and when I export it from MSAccess to an XML file and transform it with an XSL file, no results are returned. I know that the format of the XML file is correct. It must be some sort of non standard character inside one...
2
1555
by: Omari Norman | last post by:
My app needs to validate XML. That's easy enough in Unix. What is the best way to do it in Windows? The most obvious choice would of course be PyXML. However, apparently it is no longer maintained: http://sourceforge.net/project/showfiles.php?group_id=6473 so there are no Windows binaries that work with Python 2.5. Getting other XML...
2
1465
by: Robert Schweikert | last post by:
Is there a Python module which will do XSD validation? Thanks, Robert -- Robert Schweikert MAY THE SOURCE BE WITH YOU (robert.schweikert@mathworks.com) LINUX
76
3035
by: Michael Stemper | last post by:
The W3C Validator is a great help, as far as it goes. However, I'm looking for something stricter. My coding style does not allow for implicit termination of an element; my intention and desire is to explicitly terminate every element. Just last night, it took me two hours to track down some funny behavior. It turned out to be caused by...
0
7520
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...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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...
1
7470
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...
0
7809
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...
0
5088
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...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.