xml-parsing 相关问题

XML解析器遍历包含XML树的文本文档,并允许使用层次结构中的信息。将此标记用于实现XML解析器的问题,或者通过使用给定语言的现有解析器生成的问题。

如何避免 SQL Server 在使用 XQuery 时返回重复值

我在这里发现了一些与我所面临的问题很接近的问题,但没有一个解决了我的疑问。 当我将 XML 文档解析为 SQL 结果集时,我得到了一些重复值。 它...

回答 1 投票 0

ValueError:列的长度必须与 DataFrame.__setitem__(self, key, value) 中的键相同

在此输入图像描述 在此输入图像描述 ValueError:列的长度必须与键的长度相同 请帮帮我,谢谢.. 该程序用于将标签信息 xml 文件转换为 Pandas

回答 1 投票 0

XML 流式转换 (STX)

我正在使用样式表通过 STX 转换以下 XML 文档。但是,注释元素中 Kite 之后的所有内容在解析时都会被忽略。 我如何访问...

回答 1 投票 0

从 Windows 中的音频文件中提取嵌入的 XML 数据

我们有一个记录呼叫中心呼叫的平台,并在 wav 文件末尾添加一些 xml,其中保存有关该呼叫的重要元数据。 我正在尝试读取这些 wav 文件的文件夹和 p...

回答 2 投票 0

将部分 XML 字符串解析为 XElements 列表

我有一个没有根元素的部分 XML 字符串。例如。: 一些文字 其他一些文字 我需要转换这个字符串...

回答 2 投票 0

在 shell 脚本中使用 xmlstarlet 读取脚本变量值,如果该字符串不存在,则插入到特定部分下的输出 xml 文件中

我在 shell 脚本中使用的 parse yaml 实用程序通过 eval 命令生成如下变量 policy1_name='ipfilter' policy1_scope='api' policy1_apiname='apiname' policy1_inboundsession='率-

回答 1 投票 0

如何使用Python将数据追加到现有的xml文件

我必须添加一个新行,如 我必须添加一个新行,如 <?xml version="1.0" encoding="UTF-8"?> <dblogs xmlns="http://url/xml/ns/dblogs" xmlns:xsi="http://url/2001/XMLSchema-instance" xmlns:pro="http://url/xml/ns/dblogs/ns/pro" xsi:schemaLocation="http://url/xml/ns/dblogs > <changeSet author="user_id" id="v3.0.0"> <tagDatabase tag="release/v3.0.0" /> </changeSet> <include file="./file_one.xml" /> <include file="./file_two.xml" /> </dblogs> 尝试了以下代码,它打印附加值,但实际上并未附加到文件。 import xml.etree.ElementTree as ET tree = ET.parse('pqr.xml') root = tree.getroot() b = ET.SubElement(root, 'include') b.text = './dml/release/v3.0.0/abc_changelog.xml' print ET.tostring(root) 您在以下行中缺少结束语“: xsi:schemaLocation="http://url/xml/ns/dblogs > 添加此代码时,您的代码对我有用,输出如下: b'<ns0:dblogs xmlns:ns0="http://url/xml/ns/dblogs" xmlns:ns1="http://url/2001/XMLSchema-instance" ns1:schemaLocation="http://url/xml/ns/dblogs">\n\n <ns0:changeSet author="user_id" id="v3.0.0">\n\n <ns0:tagDatabase tag="release/v3.0.0" />\n\n </ns0:changeSet>\n\n <ns0:include file="./file_one.xml" />\n\n <ns0:include file="./file_two.xml" />\n\n<include>./dml/release/v3.0.0/abc_changelog.xml</include></ns0:dblogs 请注意,在您的代码中,标签添加为: <include>./dml/release/v3.0.0/abc_changelog.xml</include> 为了使其以与其他元素相同的方式显示,您还希望包含命名空间(在 Python 中使用 ElementTree 发出命名空间规范)和文件参数(如何向 ElementTree 中的 SubElement 添加属性 (Python))

回答 1 投票 0

xmlstarlet 用于在 xml 字段下插入字符串

我们有一个如下所示的policy.xml文件,需要根据条件在下(入站或后端或出站)下的xml文件的每个会话下插入如下字符串...

回答 1 投票 0

`-:55:HTML 解析器错误:htmlParseEntityRef:期待 ';'`:使用 xmllint 清理 HTML 文件?

http://journals.im.ac.cn/cjbcn/ch/reader/view_abstract.aspx?file_no=gc19010159&flag=1 我想清理上述 URL 中的文件。但 xmllint 给出以下错误。有谁知道吗...

回答 2 投票 0

如何使用java将语句导入添加到xml(架构/xsd)

我想使用java将导入语句添加到现有的schema/xsd文件中,我们是否可以将它们添加到xsd中?,我确实尝试了如下但收到错误:“org.w3c.dom.DOMException:

回答 1 投票 0

使用 xmltodict 解析 XML 后,使用 Python 字典访问键和值

给定 XML 文件: 给定 XML 文件: <?xml version="1.0" standalone="yes"?> <!--COUNTRIES is the root element--> <WORLD> <country name="ABCDEF"> <event day="323" name="$abcd"> </event> <event day="23" name="$aklm"> </event> <neighbor name="B" direction="W" friend="T"></neighbor> <neighbor name="C" direction="E"></neighbor> <neighbor name="D" direction="W"></neighbor> </country> <country name="KLMNOP"> <event day="825" name="$nmre"> </event> <event day="329" name="$lpok"> </event> <event day="145" name="$dswq"> </event> <event day="256" name="$tyul"> </event> <neighbor name="D" direction="S"/> <neighbor name="E" direction="N" friend="T"/> </country> </WORLD> 然后我使用 Python 中的“xmltodict”库解析了这个 xml 文件: import xmltodict class XMLParser: def __init__(self, xml_file_path): self.xml_file_path = xml_file_path if not self.xml_file_path: raise ValueError("XML file path is not found./n") with open (self.xml_file_path, 'r') as f: self.xml_file = f.read() def parse_xml_to_json(self): xml_file = self.xml_file dict = xmltodict.parse(xml_file, attr_prefix='') for k in dict['WORLD']['country'][1]: if k == "name": print(dict.keys()) print(dict.values()) return dict xml_file_path = "file_path" xml_parser = XMLParser(xml_file_path) data = xml_parser.parse_xml_to_json() print(data) 但是,我收到错误,无法从该字典访问键和值。 错误:AttributeError:“str”对象没有属性“keys” 我想获得以下格式的输出: 所需输出: { "neighbor": [ { "Name": "B", "direction": "W", "Type": "ABCDEF" }, { "Name": "C", "direction": "E", "Type": "ABCDEF" }, { "Name": "D", "direction": "W", "Type": "ABCDEF" }, { "Name": "D", "direction": "S", "Type": "KLMNOP" }, { "Name": "E", "direction": "N", "Type": "KLMNOP" }, ] } 请建议,我是 xml 和 python 的新手。 一个简单的嵌套循环可以在这里工作: import xml.etree.ElementTree as ET xml = '''<WORLD> <country name="ABCDEF"> <event day="323" name="$abcd"> </event> <event day="23" name="$aklm"> </event> <neighbor name="B" direction="W" friend="T"></neighbor> <neighbor name="C" direction="E"></neighbor> <neighbor name="D" direction="W"></neighbor> </country> <country name="KLMNOP"> <event day="825" name="$nmre"> </event> <event day="329" name="$lpok"> </event> <event day="145" name="$dswq"> </event> <event day="256" name="$tyul"> </event> <neighbor name="D" direction="S"/> <neighbor name="E" direction="N" friend="T"/> </country> </WORLD>''' data = {'neighbor': []} root = ET.fromstring(xml) for country in root.findall('.//country'): country_name = country.attrib['name'] for neighbor in country.findall('neighbor'): data['neighbor'].append({'Type': country_name, 'Name': neighbor.attrib['name'],'direction': neighbor.attrib['direction']}) print(data) 输出 { 'neighbor': [ { 'Type': 'ABCDEF', 'Name': 'B', 'direction': 'W' }, { 'Type': 'ABCDEF', 'Name': 'C', 'direction': 'E' }, { 'Type': 'ABCDEF', 'Name': 'D', 'direction': 'W' }, { 'Type': 'KLMNOP', 'Name': 'D', 'direction': 'S' }, { 'Type': 'KLMNOP', 'Name': 'E', 'direction': 'N' } ] }

回答 1 投票 0

Xml 反序列化

我想将xml反序列化为C#类 这是我正在使用的课程 面临获取 null 的问题12345 该字段还添加了一些额外的内容 诸如 Form_ID__c 之类的字段,

回答 1 投票 0

用python解析arxml文件

我有一个需要解析的文件,我需要信息。解析的顺序很重要。 我可以解析文件并获取信息,但不能按顺序解析。 我如何解析这些信息<...

回答 1 投票 0

如何在 Excel 中映射重复的 xml 元素

我正在处理如何映射重复的 xml 元素的问题,当我将下面的 XML 作为 XML 映射导入到 Excel 中时,我只看到 1 条记录,我需要“”的 c...

回答 2 投票 0

xml.etree.ElementTree 未解析某一特定属性值

数据文件testfile.xml是这样的: 一个...

回答 1 投票 0

Xml 转换 - 将父属性复制到子属性

我想通过将每个父PurchaseHistory的属性Type复制到其子StoreTransaction来转换下面的xml 输入XML: 我想通过将每个父级 PurchaseHistory 的属性 Type 复制到其子级 StoreTransaction 来转换下面的 xml 输入Xml: <ArrayOfStoreTransaction CustomerID="C1"> <PurchaseHistory Type="purchase.001" Count="2"> <StoreTransaction> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> <StoreTransaction> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> </PurchaseHistory> <PurchaseHistory Type="purchase.002" Count="1"> <StoreTransaction> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> </PurchaseHistory> <PurchaseHistory Type="purchase.003" Count="2"> <StoreTransaction> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> <StoreTransaction> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> </PurchaseHistory> </ArrayOfStoreTransaction> 输出XML: <ArrayOfStoreTransaction CustomerID="C1"> <StoreTransaction Type="purchase.001"> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.001"> <CustomerID>C1</CustomerID> <CustomerAccount>C1A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.002"> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.003"> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> <StoreTransaction Type="purchase.003"> <CustomerID>S3</CustomerID> <CustomerAccount>S3A</CustomerAccount> </StoreTransaction> </ArrayOfStoreTransaction> 所以我想要一个好的java库来以有效的方式转换我的xml,考虑到内存和执行时间,因为xml将非常大> 200mb 您只需要两个简单的 XSLT 模板规则即可: <xsl:template match="PurchaseHistory"> <xsl:apply-templates/> </xsl:template> <xsl:template match="StoreTransaction"> <StoreTransaction Type="{../@Type}"> <xsl:apply-templates/> </StoreTransaction> </xsl:template> 一个好的现代 XSLT 转换引擎应该能够毫无困难地处理 200Mb。如果它进入千兆字节范围,并且您使用支持 XSLT 3.0 流式传输的引擎,则此转换是完全可流式传输的。 不要浪费时间用 Java 进行编码。

回答 1 投票 0

在属性标签xml中设置url

我正在尝试将标签中的 url 添加到我的 xml 结构中。我总是得到这个: &l...

回答 1 投票 0

什么是“TBS 块”?

我计划编写一个 SAX2 XML 解析器,并且希望支持尽可能多的标准选项。然而,我真的很挠头试图理解 http://xml.org/sax/proper...

回答 1 投票 0

XML 在没有 xpath 的情况下读取嵌套节点

我有以下xml。 DocumentEntity=“借款人”|DataType=“表”|Value=“ ...

回答 1 投票 0

Ansible 无法解析模块/操作“community.general.xml”

我希望使用ansible的community.general.xml模块来解析xml。 ansible playbook 主机(运行程序)是 OLAM EE 环境(Oracle Linux 自动化管理器)提供的 docker 容器,...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.