问题标签 [xml.etree]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 如何使用python获取XML标签中子元素的大小/长度
我是 python 的新手,我想知道如何获取父标签中子元素的大小或数量让我们说participants
。这个想法是获取标签participant
内的数量。participants
这是xml:
我正在使用 xml:
import xml.etree.ElementTree as ET
作为模块
并被ET
分配dom = ET.fromstring(output)
到目前为止,为了解析 xml,我编写了以下代码:
但我想获得标签中数量的大小/长度,participant
这participants
就是我想要做的,但它没有给我长度:
我想要的输出应该是:
python - 用python转换xml文档
好的,我有一个要解析的大 xml 文档,所以我可以将它们添加到数据库中。
只要我打印结果,这工作正常,但是当我尝试
我得到这个错误
谁能帮我?
python - 使用 xml.etree.ElementTree (python) 解析 XML 时,如何区分常规空格和转义空格 ()
我xml.etree.ElementTree
用来解析 XML 文件。如何强制它去除空格文本(只是常规空格,而不是 
)或留下空格并忽略转义(保持原样)?这是我的问题:
它打印:
我需要的:
或(我可以通过其他方式逃脱):
使用解决方案xml.etree.ElementTree
更可取,因为否则我必须重写大量代码
python - 如何在 Python 中将 xml 文本与前面的空元素相关联?
我继承了一些需要在 Python 中处理的 xml。我正在使用xml.etree.cElementTree
,并且在将空元素之后出现的文本与该空元素的标签相关联时遇到了一些问题。xml 比我在下面粘贴的要复杂得多,但我已经简化了它以使问题更清楚(我希望!)。
我想要的结果是这样的字典:
期望的结果
元组还可以包含字符串(例如,('9', '1')
)。我真的不在乎这个早期阶段。
这是 XML:
测试1.xml
我尝试过的
尝试 1
尝试 2
正如您在后一种尝试中看到的那样,p
并且p.itertext()
是两种不同的长度。的值(9, 2)
是我试图与 key 关联(9, 1)
的值,而我想要关联的值(9, 2)
甚至没有出现d
(因为zip
截断了 long p.itertext()
)。
任何帮助,将不胜感激。提前致谢。
python - Python 2.6 XML 解析器断言错误
在 python 中解析我的 zenoss 服务器上的 XML 文档时出现错误。如何绕过错误/修复错误?
这是代码:
这是 XML 文件:
这是输出:
另外,如果我用 etree 做,我会得到一个 UnicodeEncodeError
代码:
输出:
python - lxml etree.parse doesn't work when used with an argument
I had a script parsing an html file which worked perfectly well until I changed it slightly, making it possible to run it from the terminal, like this:
So, when indicating the direct name of the file to parsed, it works:
Then instead of the exact name of the file I indicated a variable which should be then used as an argument in the command line:
Here is the error I get: Traceback (most recent call last):
python - 使用python获取xml节点的所有父节点
对于这个 xml
我如何lxml
etree
在 python 中使用节点的所有父节点。
预期输出:输入 orgid=126 ,它将返回所有的父母喜欢,
python - 使用 etree Python 解析 xml
对于这个 xml
我怎样才能得到locationID
地址A
,使用etree
。
这是我的代码,
得到输出None
,我在这里做错了什么?
python - 如何制作生成的 xml 的样本?
我使用 lxml.etree.Element 方法创建 xml 结构
我需要执行以下查询:
但我收到以下错误消息:
回溯(最近一次调用最后):文件“C:\VINT\OPENSERVER\OpenServer\domains\localhost\python\parse_html\6_first_store_names_cat_full_xml_nested\q.py”,第 9 行,在 doc = lxml.html.document_fromstring(parent) 文件中C:\Python33\lib\site-packages\lxml\html__init__.py”,第 600 行,在 document_fromstring value = etree.fromstring(html, parser, **kw) 文件“lxml.etree.pyx”,第 3003 行,在lxml.etree.fromstring (src\lxml\lxml.etree.c:67277) 文件“parser.pxi”,第 1784 行,在 lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:101615) ValueError: can只解析字符串
>
请帮帮我
python - 在python中使用lxml解析标签内的XML数据
我的问题是关于如何获取存储在不允许结束标签的标签中的信息。这是相关的xml:
我希望在这里提取 xlink:href url。如您所见,uws:result 标签不需要结束标签。此外,在 python 中工作时,拥有 'uws:' 使得处理它们有点棘手。这是我到目前为止所尝试的:
其中 xmlresponse.content 是要解析的 xml 数据。这返回的是
这表明它只找到换行符,因为我真正想要的内容包含在结果标签内的标签中。任何想法将不胜感激。