xml-parsing 相关问题

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

如何在 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

如何在Python中解析类似xml的文本文件?

我有一个类似 XML 语言的文本文件,如下所示: ...

回答 1 投票 0

Xpath 使用无输出

我有一个我正在尝试解析的 xml 的 API 输出 下面是一个例子。 我正在使用 Power Automate 并尝试使用 xpath 我有一个 xml 的 API 输出,我正在尝试解析 下面是一个例子。 我正在使用 Power Automate 并尝试使用 xpath <?xml version="1.0"?> <requests> <request id="31998"> <employee id="6505">Peter Parker</employee> <start>2025-07-11</start> <end>2025-07-13</end> <created>2025-07-16</created> <status lastChanged="2024-01-16" lastChangedByUserId="91210">approved</status> <type id="84" icon="time-off-calendar">Vacation</type> <amount unit="days">2</amount> <dates> <date ymd="2024-03-11" amount="1"/> <date ymd="2024-03-12" amount="1"/> </dates> <notes> <note from="employee">Work Sucks and i dont wont to be here</note> </notes> </request> 我的 Xpath 看起来像这样 xpath(xml(outputs('Compose')), '(//request/@id)') 我的输出是这样的 [ "id=\"31998\"", "id=\"32214\"", "id=\"32339\"" ] 我只想要这里的数字,所以我尝试了以下 xpath(xml(outputs('Compose')), 'string(//request/@id)') 这只返回 31998 这对我来说没有好处,我想要所有的结果。就像第一个例子一样。 所以我尝试了这个语法 xpath(xml(outputs('Compose')), 'string(//request/@id/text()') 和 xpath(xml(outputs('Compose')), 'string(//request/@id[text()]') 这两者都会产生 null 我现在很茫然,失去了所有的耐心 可爱的小伙伴们能帮忙吗 很好,我也无法让它发挥作用。最坏的情况是,您可能需要进行一些字符串操作。 或者,您可以使用 高级数据操作 连接器和 XmlToJson 操作... 结果 ...另一种选择是将 XML 转换为 JSON 并使用 Select 操作对其进行处理... 表达式 来自 = json(xml(variables('XML')))['requests']['request'] 地图项目 = item()[string('@id')] 结果 使用 Powershell 和 Xml Linq 将数据解析到表中,然后导出到 CSV using assembly System.Xml.Linq $inputFilename = 'c:\temp\test.xml' $outputFilename = 'c:\temp\test.csv' $doc = [System.Xml.Linq.XDocument]::Load($inputFilename) $table = [System.Collections.ArrayList]::new() foreach($request in $doc.Descendants('request')) { $requestId = $request.Attribute('id').Value $employee = $request.Element('employee') $employeeId = $employee.Attribute('id').Value $employeeName = $employee.Value $newRow = [psCustomObject]@{ RequestId = $requestId EmployeeId = $employeeId EmployeeName = $employeeName } $table.Add($newRow) | out-null } $table | Export-CSV -path $outputFilename -NoTypeInformation 请求将如下所示 "RequestId","EmployeeId","EmployeeName" "31998","6505","Peter Parker"

回答 2 投票 0

发票哈希 API 正文与 XML 的(计算的)哈希不匹配

我的 Zatca 入门在两个月前上次使用时工作正常。我用 XML 测试了整个过程,一切似乎都正常。但从昨天开始,我尝试使用相同的鳕鱼登船......

回答 1 投票 0

我如何用这种格式构建xml?

我正在尝试使用 php 从关联数组创建 xml。为了构建我的 xml,我使用 SimpleXMLElement 我需要包含这个结构: 我正在尝试使用 php 从关联数组创建 xml。为了构建我的 xml,我使用 SimpleXMLElement 我需要包含这个结构: <pt:request xmlns:pt="urn:logalty:schemas:core:1.0" xmlns:identity="urn:logalty:schemas:core:identity:1.0" xmlns:process_meta="urn:logalty:schemas:process:meta:1.0" xmlns:ptforms="urn:logalty:schemas:forms:1.0" xmlns:request_meta="urn:logalty:schemas:request:meta:1.0"> <pt:request_meta> <request_meta:service>PT0005_ACCEPTANCEXPRESS</request_meta:service> <request_meta:time2close unit="d" value="28"/> <request_meta:time2save unit="d" value="1825"/> <request_meta:lopd>0</request_meta:lopd> <request_meta:retryprotocol>3</request_meta:retryprotocol> <request_meta:synchronous>false</request_meta:synchronous> <request_meta:tsa>0</request_meta:tsa> <request_meta:userdefined name="LGT_SDKJava">4.13.2</request_meta:userdefined> </pt:request_meta> </pt:request> 在我的 SimpleXMLElement 实例中,我正在做: new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><pt:request xmlns:pt="urn:logalty:schemas:core:1.0" xmlns:identity="urn:logalty:schemas:core:identity:1.0" xmlns:process_meta="urn:logalty:schemas:process:meta:1.0" xmlns:ptforms="urn:logalty:schemas:forms:1.0" xmlns:request_meta="urn:logalty:schemas:request:meta:1.0"><pt:request_meta></pt:request_meta></pt:request>'); 我的 xml 创建正常,但是当我在记事本 ++ 中显示它并补充 XML 时,我可以看到我的标签格式错误: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <pt:request xmlns:pt="urn:logalty:schemas:core:1.0" xmlns:identity="urn:logalty:schemas:core:identity:1.0" xmlns:process_meta="urn:logalty:schemas:process:meta:1.0" xmlns:ptforms="urn:logalty:schemas:forms:1.0" xmlns:request_meta="urn:logalty:schemas:request:meta:1.0"> <pt:request_meta/> <pt:service>instalacion_id_1</pt:service> <pt:0>request_meta:time2close unit="d" value="28"</pt:0> <pt:1>request_meta:time2save unit="d" value="1825"</pt:1> <pt:lopd>0</pt:lopd> <pt:retryprotocol>3</pt:retryprotocol> <pt:synchronous/> <pt:tsa>0</pt:tsa> <pt:userdefined name="php">8.1.6</pt:userdefined> </pt:request> 任何人都可以帮助我创建具有正确结构的XMl?我不知道如何使用这些信息来制作我的标签,例如: <request_meta:time2close unit="d" value="28"/> 我的数组数据是: $logalty_data = [ 'request_meta:service' => 'instalacion_id_'.$id, 'request_meta:time2close unit="d" value="28"', 'request_meta:time2save unit="d" value="1825"', 'request_meta:lopd' => 0, 'request_meta:retryprotocol' => 3, 'request_meta:synchronous' => false, 'request_meta:tsa' => 0, 'request_meta:userdefined name="php"' => '8.1.6' ]; 更新: 我已经用标签解决了我的问题:<request_meta:time2close unit="d" value="28"/> 我在这个索引中添加我的数组:=> ""用这种方式,创建一个空标签并关闭它: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <pt:request xmlns:pt="urn:logalty:schemas:core:1.0" xmlns:identity="urn:logalty:schemas:core:identity:1.0" xmlns:process_meta="urn:logalty:schemas:process:meta:1.0" xmlns:ptforms="urn:logalty:schemas:forms:1.0" xmlns:request_meta="urn:logalty:schemas:request:meta:1.0"> <pt:request_meta/> <pt:service>instalacion_id_1</pt:service> <pt:time2close unit="d" value="28"/> <pt:time2save unit="d" value="1825"/> <pt:lopd>0</pt:lopd> <pt:retryprotocol>3</pt:retryprotocol> <pt:synchronous/> <pt:tsa>0</pt:tsa> <pt:userdefined name="php">8.1.6</pt:userdefined> </pt:request> 但我的标签仍然有问题<pt:request_meta/>只有关闭标签,没有打开标签 如果你想添加一些东西作为子元素,你必须这样做。 这会将包装元素添加为根元素的子元素,然后您可以直接将子元素添加到包装元素。 <?php $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><pt:request xmlns:pt="urn:logalty:schemas:core:1.0" xmlns:identity="urn:logalty:schemas:core:identity:1.0" xmlns:process_meta="urn:logalty:schemas:process:meta:1.0" xmlns:ptforms="urn:logalty:schemas:forms:1.0" xmlns:request_meta="urn:logalty:schemas:request:meta:1.0"></pt:request>'); $wrapper = $xml->addChild('pt:request_meta'); $wrapper->addChild('request_meta:service', 'instalacion_id_1', 'request_meta'); // add the rest of the data $xml->saveXML('test.xml'); 此代码片段产生的输出是 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <pt:request xmlns:pt="urn:logalty:schemas:core:1.0" xmlns:identity="urn:logalty:schemas:core:identity:1.0" xmlns:process_meta="urn:logalty:schemas:process:meta:1.0" xmlns:ptforms="urn:logalty:schemas:forms:1.0" xmlns:request_meta="urn:logalty:schemas:request:meta:1.0"> <pt:request_meta> <request_meta:service xmlns:request_meta="request_meta">instalacion_id_1</request_meta:service> </pt:request_meta> </pt:request>

回答 1 投票 0

将时间跨度除以2?

我有两次,它们的值是从网络上的 XML 中获取的。 XElement xmlWdata = XElement.Parse(e.Result); string SunRise = xmlWdata.Element("sun").Attribute("rise").Value; 字符串日落 =

回答 3 投票 0

LPX-00217: 无效字符 15576961 (U+EDAF81) - 如何通过 Notepad 或 Notedpad++ 查找无效字符?

我收到错误: ORA-31011: XML 解析失败 ORA-19202: XML 处理中发生错误 LPX-00217: 无效字符 15576961 (U+EDAF81) 我有包含客户敏感数据的 xml 文件。如何找到

回答 1 投票 0

如何使用 XML::Simple 解析配置文件?

Perl 片段: 我的 $xml = 新 XML::Simple( 关键属性=>{ 属性 => '属性名称', }, 力数组 => 1, ContentKey => '-内容'); 我的 $config = $xml->X...

回答 1 投票 0

如何使用 XSLT 将名称空间添加到 XML 的根元素?

我有一个输入 XML 美国 A 我的输出应该是这样的 我有一个输入 XML <Request> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> 我的输出应该是这样的 <Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://hgkl.kj.com"> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> 请让我知道如何添加多个命名空间和默认命名空间,如上面的 XML。 这是我在 XSLT 2.0 中的做法... XML 输入 <Request> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> XSLT 2.0 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="*" priority="1"> <xsl:element name="{local-name()}" namespace="http://hgkl.kj.com"> <xsl:namespace name="xsi" select="'http://www.w3.org/2001/XMLSchema-instance'"/> <xsl:namespace name="xsd" select="'http://www.w3.org/2001/XMLSchema'"/> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> </xsl:stylesheet> XML 输出 <Request xmlns="http://hgkl.kj.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Info> <Country>US</Country> <Part>A</Part> </Info> </Request> 这里有一个 XSLT 1.0 选项,它会产生相同的输出,但要求您知道根元素的名称... <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|text()|comment()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="/Request"> <Request xmlns="http://hgkl.kj.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsl:apply-templates select="@*|node()"/> </Request> </xsl:template> <xsl:template match="*"> <xsl:element name="{local-name()}" namespace="http://hgkl.kj.com"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> </xsl:stylesheet> 这个答案显然没有优化,但会提示您如何让它在 4.2 版本的命名空间和非命名空间 XML 上工作: 这里是parseXml的body方法 JAXBContext jc = JAXBContext.newInstance(VAST.class); Unmarshaller u = jc.createUnmarshaller(); // should be optimized TransformerFactory tf = TransformerFactory.newInstance(); StringWriter sw = new StringWriter(); URL urlXslt = VastParser.class.getClassLoader().getResource("xslt/vast_4.2.xslt"); File fileXslt = new File(urlXslt.toURI()); Transformer t = tf.newTransformer(new StreamSource(new FileInputStream(fileXslt))); // transform original XML with XSLT to always add the namespace in the parsing t.transform(new StreamSource(new StringReader(xmlString)), new StreamResult(sw)); // unmarshall transformed XML JAXBElement<VAST> foo = u.unmarshal(new StreamSource(new StringReader(sw.toString())), VAST.class); return new CustomVast(foo.getValue()); src/main/resources/xslt/vast_4.2.xslt 是: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|text()|comment()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- adds the xmlns part to the VAST element --> <xsl:template match="/VAST"> <VAST xmlns="http://www.iab.com/VAST"> <xsl:apply-templates select="@*|node()"/> </VAST> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 这样,两个单元测试都适用于 4.2 部分。

回答 2 投票 0

通过 Python 使用 CSV 的 XML 嵌套格式

我有一个 csv 格式文件,我正在尝试使用 python 将其转换为 xml。现在的逻辑是在 csv 中的每一行构建一个 xml 块。 我正在寻找 xml 中某些元素的嵌套。 对于

回答 1 投票 0

Python lxml 通过 id-tag 查找元素

我正在开发一个Python程序来保存储藏室的库存。在 XML 文档中,将保留碳粉量,我希望我的 python 程序能够添加、删除和显示

回答 2 投票 0

将嵌套 XML 转换为 R 中的数据帧

我正在尝试将 ClinicalTrials.gov 中的 XML 数据转换为数据框架,以便在 R 中进行分析。我有一个 URL,允许我在每项研究中选择我要查找的特定字段。每行和

回答 1 投票 0

获取XML字符串中二级标签的名称

我正在尝试从 XML 文件获取数据并将其转换为 JSON。 $xml = simplexml_load_file('types.xml','SimpleXMLElement',LIBXML_NOCDATA); $json = json_encode($xml); $array = json_decode(...

回答 2 投票 0

如何在java springboot中的列表元素中增加@XmlElement名称

`我需要实现这个输出: 价值 价值 `我需要实现这个输出: <Entity> <MRA_BALANCE_SHEET> <R0030C0030>value</R0030C0030> <R0030C0040>value</R0030C0040> </MRA_BALANCE_SHEET> <MRA_BALANCE_SHEET> <R0040C0030>value</R0040C0030> <R0040C0040>value</R0040C0030> </MRA_BALANCE_SHEET> </Entity> 每个元素,“R003O”都会增加 10。因此,正如您在下一个列表中看到的,R0030C0030 将增加 10,=“R0040C0030” 需要帮助` 这是我的示例实体 private String PHP; private String PHPUSD; @XmlElement(name = "R0030C0010") public String getPHP() { return PHP; } 您应该创建一个元素名称作为键、元素值作为值的映射。然后,您可以使用 XStream 或任何其他库将此地图转换为 xml。 请参阅如何将 XML 转换为 java.util.Map,反之亦然?了解更多信息。

回答 1 投票 0

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