sax

How to use xml sax parser to read and write a large xml?

前提是你 提交于 2019-11-29 06:45:32
I'm trying to remove all the project1 nodes (along with their child elements) from the below sample xml document ( original document is about 30 GB ) using SAX parser.It would be fine to have a separate modified file or ok with the in-line edit. sample.xml <ROOT> <test src="http://dfs.com">Hi</test> <project1>This is old data<foo></foo></project1> <bar> <project1>ty</project1> <foo></foo> </bar> </ROOT> Here is my attempt.. parser.py from xml.sax.handler import ContentHandler import xml.sax class MyHandler(xml.sax.handler.ContentHandler): def __init__(self, out_file): self._charBuffer = []

SAX vs XmlTextReader - SAX in C#

╄→гoц情女王★ 提交于 2019-11-28 23:32:21
I am attempting to read a large XML document and I wanted to do it in chunks vs XmlDocument 's way of reading the entire file into memory. I know I can use XmlTextReader to do this but I was wondering if anyone has used SAX for .NET? I know Java developers swear by it and I was wondering if it is worth giving it a try and if so what are the benefits in using it. I am looking for specifics. If you're talking about SAX for .NET , the project doesn't appear to be maintained. The last release was more than 2 years ago. Maybe they got it perfect on the last release, but I wouldn't bet on it. The

What is the difference between localname and qname?

泪湿孤枕 提交于 2019-11-28 19:12:24
When using SAX to parse an XML file in Java, what is the difference between the parameters localname and qname in SAX methods such as startElement(String uri, String localName,String qName, Attributes attributes) ? The qualified name includes both the namespace prefix and the local name: att1 and foo:att2 . Sample XML <root xmlns="http://www.example.com/DEFAULT" att1="Hello" xmlns:foo="http://www.example.com/FOO" foo:att2="World"/> Java Code: att1 Attributes without a namespace prefix do not pick up the default namespace. This means while the namespace for the root element is "http://www

How to select saxon TransformerFactory in Java

99封情书 提交于 2019-11-28 17:35:30
问题 In my web application I need to use Saxon TransformerFactory in order to use XSLT 2.0 but I can't use setProperty method because I don't have this right on the web server and there is a Security Manager. So I have read that it should be possible to do this: Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API will look for a classname in the file META-INF/services/javax.xml.transform.TransformerFactory in jars available to the

How to set Saxon as the Xslt processor in Java?

血红的双手。 提交于 2019-11-28 15:40:12
This is a simple question, but one I cannot find the answer to. I have an XSLT 2.0 stylesheet that I'm trying to process in Java. It relies on XSL elements from Saxon. My current class works fine with simple XSLT 1.0, but I'm getting errors about unrecognized elements with my 2.0 XSLT built with Saxon. I cannot figure out how to tell Java to use Saxon as the processor. I'm using javax.xml.transform in my class. Is this a property I can set? What do I set it to? Thanks! Edited I figured out how to set the property to use Saxon, but now I'm getting this error. Provider net.sf.saxon

XML parsing - ElementTree vs SAX and DOM

橙三吉。 提交于 2019-11-28 15:19:10
Python has several ways to parse XML... I understand the very basics of parsing with SAX . It functions as a stream parser, with an event-driven API. I understand the DOM parser also. It reads the XML into memory and converts it to objects that can be accessed with Python. Generally speaking, it was easy to choose between the two depending on what you needed to do, memory constraints, performance, etc. (Hopefully I'm correct so far.) Since Python 2.5, we also have ElementTree . How does this compare to DOM and SAX? Which is it more similar to? Why is it better than the previous parsers?

Android: Sax parsing returns null values and retrieve values in tags of same name

我只是一个虾纸丫 提交于 2019-11-28 11:48:22
I have these XML on a URL <?xml version="1.0" encoding="ISO-8859-1" ?> <Phonebook> <PhonebookEntry> <firstname>John</firstname> <lastname>Connor</lastname> <Address>5,Downing Street</Address> <Phone loc="home">9875674567</Phone> <Phone loc="work">9875674567</Phone> <Phone loc="mobile">78654562341</Phone> </PhonebookEntry> <PhonebookEntry> <firstname>John</firstname> <lastname>Smith</lastname> <Address>6,Downing Street</Address> <Phone loc="home">678-56-home</Phone> <Phone loc="work">678-59-work</Phone> <Phone loc="mobile">678-85-mobile</Phone> </PhonebookEntry> </Phonebook> I was able to

error in updating android sdk (org.xml.sax.SAXParseException)

烂漫一生 提交于 2019-11-28 11:28:23
问题 There is a common problem in using android sdk manager but there isn't any solution for this problem all over the web even in the stackoverflow : for updating components of android sdk I write in the command prompt: C:\sdk\tools\bin>sdkmanager --list the erros that appear are these: Warning: Errors during XML parse: Warning: White spaces are required between publicId and systemId. Warning: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 62; White spaces are required between

Sax parsing and encoding

你离开我真会死。 提交于 2019-11-28 11:24:24
I have a contact that is experiencing trouble with SAX when parsing RSS and Atom files. According to him, it's as if text coming from the Item elements is truncated at an apostrophe or sometimes an accented character. There seems to be a problem with encoding too. I've given SAX a try and I have some truncating taking place too but haven't been able to dig further. I'd appreciate some suggestions if someone out there has tackled this before. This is the code that's being used in the ContentHandler: public void characters( char[], int start, int end ) throws SAXException { // link = new String

BlackBerry/J2ME - SAX parse collection of objects with attributes

匆匆过客 提交于 2019-11-28 10:59:19
问题 I have a problem with using the SAX parser to parse a XML file. It is a complex XML file, it is like the following. <Objects> <Object no="1"> <field name="PID">ilives:87877</field> <field name="dc.coverage">Charlottetown</field> <field name="fgs.ownerId">fedoraAdmin</field> </Object> <Object no="2">...... I am confused how to get the names in each field, and how to store the information of each object. import java.util.Enumeration; import java.util.Hashtable; public class XMLObject { private