“Content is not allowed in prolog” error yet nothing before XML declaration

Elaborating on what @MartinHonnen has already helpfully commented… The error, Content is not allowed in prolog. arises because the XML prolog, which is everything before the root element in an XML document, has textual content that is not allowed. The error does not necessarily have to have occurred before the XML declaration. Specifically, the prolog … Read more

Reading large XML documents in .net

You basically have to use the “pull” model here – XmlReader and friends. That will allow you to stream the document rather than loading it all into memory in one go. Note that if you know that you’re at the start of a “small enough” element, you can create an XElement from an XmlReader, deal … Read more

PHP generated XML shows invalid Char value 27 message

A useful function to get rid of that error is suggested on this website. http://www.phpwact.org/php/i18n/charsets#common_problem_areas_with_utf-8 When you put utf-8 encoded strings in a XML document you should remember that not all utf-8 valid chars are accepted in a XML document http://www.w3.org/TR/REC-xml/#charsets So you should strip away the unwanted chars, else you’ll have an XML fatal … Read more

lxml etree xmlparser remove unwanted namespace

import io import lxml.etree as ET content=””‘\ <Envelope xmlns=”http://www.example.com/zzz/yyy”> <Header> <Version>1</Version> </Header> <Body> some stuff </Body> </Envelope> ”’ dom = ET.parse(io.BytesIO(content)) You can find namespace-aware nodes using the xpath method: body=dom.xpath(‘//ns:Body’,namespaces={‘ns’:’http://www.example.com/zzz/yyy’}) print(body) # [<Element {http://www.example.com/zzz/yyy}Body at 90b2d4c>] If you really want to remove namespaces, you could use an XSL transformation: # http://wiki.tei-c.org/index.php/Remove-Namespaces.xsl xslt=””‘<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> … Read more

How can I access namespaced XML elements using BeautifulSoup?

BeautifulSoup isn’t a DOM library per se (it doesn’t implement the DOM APIs). To make matters more complicated, you’re using namespaces in that xml fragment. To parse that specific piece of XML, you’d use BeautifulSoup as follows: from BeautifulSoup import BeautifulSoup xml = “””<xml> <web:Web> <web:Total>4000</web:Total> <web:Offset>0</web:Offset> </web:Web> </xml>””” doc = BeautifulSoup( xml ) print … Read more

How to parse XML with jsoup

It seems the latest version of Jsoup (1.6.2 – released March 28, 2012) includes some basic support for XML. String html = “<?xml version=\”1.0\” encoding=\”UTF-8\”><tests><test><id>xxx</id><status>xxx</status></test><test><id>xxx</id><status>xxx</status></test></tests></xml>”; Document doc = Jsoup.parse(html, “”, Parser.xmlParser()); for (Element e : doc.select(“test”)) { System.out.println(e); } Give that a shot..

How to parse same name tag in Android XML DOM Parsing?

Your getValue() method gets MyResource element, from there, you need to get all Items under MyResource and do getElementValue(). Example code is: public Map getValue(Element item, String str) { NodeList n = item.getElementsByTagName(str); for (int i = 0; i < n.getLength(); i++) { System.out.println(getElementValue(n.item(i))); } //Here store it in list/map and return list/map instead of … Read more