问题标签 [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 - 查询:用 xml.etree 解析以下 xml 代码?
问题陈述:
鉴于下面给出的 xml,我想编写一个简单的脚本来生成(http)www.herp.com/和(http)www.herp.com/derp。可以想象,对于我遇到的每条应用程序路径。也就是说,如果我有更多,例如:<application path = "wassup" applicationPool="derp />
,我也想要(http)www.herp.com/wassup。
尝试的解决方案:
我正在使用以下代码:
但是,这显然只会给我:
我无法在属性中看到任何指向我的东西<application path = "i want this stuff" />
我尝试使用 site.tag、site.text、site.attrib 和 site.tail,但这些都不能帮助我查看构建 url 的应用程序路径。如何解析此 xml 代码以提供名称和路径属性?
因此,鉴于这里的出色建议。我尝试了以下代码:
我收到以下错误。
标签也有类似的错误。基本上,如果我使用site.find('application')
它会给我第一个<application path ="/" applicationPool="whatever"/>
,但我找不到它下面的其余部分。对不起。显然,我运行它的这个特定配置具有我不知道的网站依赖关系。我是新来的工作。
研究来源:
- RTFM:https ://docs.python.org/2/library/xml.etree.elementtree.html
- http://luisartola.com/software/2010/easy-xml-in-python/
- 谷歌/这里
注意: 我有多个 *.config 文件,使用脚本进行解析是可行的方法。我知道一些 GUI 工具可以做基本的事情,但在这里不合适。
xml - Specifying xml parsing with multiple roots having the same name using etree
I'm using xml.etree.ElementTree to parse an xml file in the form-
I am then separating out the time values and comparing them to get the smallest possible value. However, I'm not sure how to do this without also ending up getting the distance value, which messes up my dataset. This is the code I have so far for fetching anything under the values root-
Is there a way I can modify this to only get the values under duration and not distance? Thank you in advance.
python - 使用 lxml.etree 解析 python alexa 结果
我正在使用来自 aws 的 alexa api,但我发现很难解析结果以获得我想要的
alexa api返回一个对象树<type 'lxml.etree._ElementTree'>
我使用此代码打印树
我在下面得到 xml
我root.find('LinksInCount').text
用来获取元素的值,但它不起作用。
我想知道如何获取3453627
文本aws:LinksInCount
python - 读写etree
我是 etree 的新手。我想阅读 etree 并将该特定信息放入另一种文件格式,如 html、xml 等。我检查过,现在我可以做到这一点,但现在其他方式呢?就像,如果我想读取任何其他文件格式并生成或写入 etree。请给我一些建议或示例以继续进行。
python - .findall() 可以匹配 python etree 中的多个值吗?
有没有办法使用匹配树中的多个元素.findall()
?
我想这样做:
这是我的工作(这在我的情况下有效,因为我在同一个 XML 中没有 e1 和 e2):
我正在解析具有相似结构但名称不同的 XML 文件。C# 允许“element1 | element2”匹配。
python - 如何使用 xml.etree.ElementTree 访问标签之间的文本
我正在尝试使用 .xml 提取 XML 文档的两个标签之间的文本值xml.etree.ElementTree
。在以下示例中,这将是值text two
和text three
。我只能提取text one
. 我如何从<c>
标签中找到其他文本?
python - 如何在 python 中处理 xml 命名空间?
我不会解析 xml 文件,但我想在 python 中移动它。(即 etree) 我知道 etree 的基本知识,但我只想知道 xml 命名空间。我在代码中有 3 个命名空间。这是我要转移的代码。
<?xml version="1.0" encoding="UTF-8" Standalone="yes"?><ns1:g2sMessage xmlns:ns1="http://www.gamingstandards.com/g2s/schemas/v1.0.3"> <ns1:g2sBody ns1:dateTimeSent="2014-08-14T15:30:48.692+09:00" ns1:egmId="TestAppEGMID" ns1:hostId="1"><ns1:communications ns1:deviceId="0" ns1 :sessionId="1001" ns1:sessionType="G2S_request" ns1:timeToLive="100" ns1:commandId="1001" ns1:dateTime="2014-08-14T06:30:48.696Z"><ns1:keepAlive/> </ns1:communications></ns1:g2sBody></ns1:g2sMessage>TestAppEGMID1
有人有想法吗?
python - Python:如何用新节点替换 XML 文件中的字符?
我想用新节点“<colon/>”替换下面节点中的所有分号“:”实例,如下所示。
我要这个:
<shortName>触发器:数字边缘:源</shortName>
变成这样:
<shortName>触发器<colon/>数字边缘<colon/>来源</shortName>
我已经尝试过使用搜索和替换字符串,但是当我得到输出时,所有的 "< >" 都更改为 < 和 > 。谁能建议任何技术来做到这一点。谢谢你
python - xml.etree.ElementTree.Element.remove 的项目和列表(项目)中的 x 之间的区别
下面我有一个简单的 XML 结构
在此示例中,我尝试删除任何override
.
假设我有以下设置代码:
如果我执行以下操作,则仍然存在:
但是,如果我指定list(parent)
而不是 just in parent
,那么它可以工作:
为什么会这样?如果我child
在删除之前打印出来,我可以清楚地看到相同的元素以两种方式打印。那么这里到底发生了什么?
python - 将 XML 子树写入文件
所以我有一个巨大的 XML 文件,但只想要另一个文件中的一部分。因此我想提取它,然后我可以在不影响原始文件的情况下对其进行一些工作。
这是基本思想
简单地说我想将 b 提取到另一个文件并编辑它
这如何在python中完成
我目前正在尝试使用xml.etree.ElementTree
但似乎无法正确处理。
按照要求我的错误
1.
2.
老实说,我只是在猜测
不要误会我的意思,我确实在网上查过,但找不到任何东西。