minidom

How to parse unicode strings with minidom?

谁说胖子不能爱 提交于 2019-12-23 07:03:09
问题 I'm trying to parse a bunch of xml files with the library xml.dom.minidom, to extract some data and put it in a text file. Most of the XMLs go well, but for some of them I get the following error when calling minidom.parsestring(): UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 5189: ordinal not in range(128) It happens for some other non-ascii characters too. My question is: what are my options here? Am I supposed to somehow strip/replace all those non-English

Using Python to scrape DataSet and Query data from RDL

有些话、适合烂在心里 提交于 2019-12-23 03:17:19
问题 I set out today with the intent to parse an SSRS RDL file (XML) using Python in order to gather the DataSet and Query data. A recent project has me back tracking on a variety of reports and data sources with the intention of consolidating and cleaning up what we have published. I was able to use this script to create a CSV file with the following columns: system path|report file name|command type|command text| It's not very elegant, but it works. What I'm hoping to be able to do with this

MemoryError with minidom in Python

蓝咒 提交于 2019-12-22 13:59:57
问题 I've got a MemoryError with minidom parser in Python. I'm reading 8000 small files (most under 50 Kb) and I've got this error after 2500 reading...` Traceback (most recent call last): File "C:\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 1307, in <module> debugger.run(setup['file'], None, None) File "C:\eclipse\plugins\org.python.pydev.debug_2.4.0.2012020116\pysrc\pydevd.py", line 1060, in run pydev_imports.execfile(file, globals, locals) #execute the script

Commenting and uncommenting XML via Python

末鹿安然 提交于 2019-12-22 11:10:08
问题 I would like to know of a way to comment and uncomment an element in XML using Python. <target depends="create-build-dir" name="build-Folio"> <property name="project.name" value="Folio"/> <ant antfile="build.xml" dir="Folio/FolioUI" inheritall="false" target="package"/> <ant antfile="build.xml" dir="Folio/Folio" inheritall="false" target="package"/> </target> How can I get it to look like this: <target depends="create-build-dir" name="build-Folio"> <property name="project.name" value="Folio"/

Node.toprettyxml() adds newlines to DOCTYPE in Python

ⅰ亾dé卋堺 提交于 2019-12-22 08:18:41
问题 When using prettify my DOCTYPE is broken into three lines. How can I keep it on one line? The "broken" output: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE smil PUBLIC '-//W3C//DTD SMIL 2.0//EN' 'http://www.w3.org/2001/SMIL20/SMIL20.dtd'> <smil xmlns="http://www.w3.org/2001/SMIL20/Language"> <head> <meta base="rtmp://cp23636.edgefcs.net/ondemand"/> </head> <body> <switch> <video src="mp4:soundcheck/1/clay_aiken/02_sc_ca_sorry_256.mp4" system-bitrate="336000"/> <video src="mp4:soundcheck/1

Get node name with minidom

北慕城南 提交于 2019-12-22 04:13:18
问题 Is it possible to get the name of a node using minidom? For example I have a node: <heading><![CDATA[5 year]]></heading> What I'm trying to do, is store the value heading so that I can use it as a key in a dictionary. The closest I can get is something like: [<DOM Element: heading at 0x11e6d28>] I'm sure I'm overlooking something very simple here, thanks. 回答1: Is this what you mean? tag= node.tagName d[tag]= node tagName is defined in DOM Level 1 Core, the basic standard that minidom (mostly)

How to comment out an XML Element (using minidom DOM implementation)

ε祈祈猫儿з 提交于 2019-12-21 02:43:44
问题 I would like to comment out a specific XML element in an xml file. I could just remove the element, but I would prefer to leave it commented out, in case it's needed later. The code I use at the moment that removes the element looks like this: from xml.dom import minidom doc = minidom.parse(myXmlFile) for element in doc.getElementsByTagName('MyElementName'): if element.getAttribute('name') in ['AttribName1', 'AttribName2']: element.parentNode.removeChild(element) f = open(myXmlFile, "w") f

Get Element value with minidom with Python

血红的双手。 提交于 2019-12-17 10:13:22
问题 I am creating a GUI frontend for the Eve Online API in Python. I have successfully pulled the XML data from their server. I am trying to grab the value from a node called "name": from xml.dom.minidom import parse dom = parse("C:\\eve.xml") name = dom.getElementsByTagName('name') print name This seems to find the node, but the output is below: [<DOM Element: name at 0x11e6d28>] How could I get it to print the value of the node? 回答1: It should just be name[0].firstChild.nodeValue 回答2: Probably

PyException: ImportError: No module named domreg

跟風遠走 提交于 2019-12-13 09:46:51
问题 I am getting the below error while running this script ( "from xml.dom import minidom" ) from chaquopy androi application python console. PyException: ImportError: No module named domreg 回答1: There was a bug which prevented implicit relative imports from working with the import hook enabled. This has been fixed in version 0.4.4 which is available now (https://github.com/chaquo/chaquopy/issues/12). 来源: https://stackoverflow.com/questions/46885861/pyexception-importerror-no-module-named-domreg

How to check if an xml node has children in python with minidom?

╄→гoц情女王★ 提交于 2019-12-13 05:19:47
问题 How to check if an xml node has children in python with minidom? I'm writing an recursive function to remove all attributes in an xml file and I need to check if an node has child nodes before calling the same function again. What I've tried: I tried to use node.childNodes.length, but didn't have much luck. Any other suggestions? Thanks My Code: def removeAllAttributes(dom): for node in dom.childNodes: if node.attributes: for key in node.attributes.keys(): node.removeAttribute(key) if node