While parsing xml file using DOM parser if we know the tag names then we can parse the text using getElementsByTagName.But I want to parse the xml file and get the text nodes and edit them but every time the tag names are not knows, Is there any way to edit the xml file if we
don't know the tags?
Finding text nodes in xml file
Page 1 of 11 Replies - 545 Views - Last Post: 01 April 2012 - 03:08 PM
Replies To: Finding text nodes in xml file
#2
Re: Finding text nodes in xml file
Posted 01 April 2012 - 03:08 PM
Have you looked at python's SAX API?
http://docs.python.o...xml.sax.handler
Check out the xml.sax.ContentHandler class, which provides (among other things) the startElement method. This method is called when the parser encounters -- you guessed it -- a start tag. The name of the tag is provided in the 'name' parameter. Here is the method signature.
The following is quoted straight from the documentation...
"The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an object of the Attributes interface..."
Take a look and let us know if you have any specific questions.
http://docs.python.o...xml.sax.handler
Check out the xml.sax.ContentHandler class, which provides (among other things) the startElement method. This method is called when the parser encounters -- you guessed it -- a start tag. The name of the tag is provided in the 'name' parameter. Here is the method signature.
ContentHandler.startElement(name, attrs)
The following is quoted straight from the documentation...
"The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an object of the Attributes interface..."
Take a look and let us know if you have any specific questions.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|