xml 相关问题

可扩展标记语言(XML)是一种灵活的结构化文档格式,用于定义人类和机器可读的编码规则。

Amazon API JSON 响应

我正在使用 Amazon AWSECommerceService API 从 Amazon 网站获取一些信息并将其用于我的页面/网站。我正在发送 REST 请求,我收到的响应采用 XMl 形式...

回答 1 投票 0

以编程方式将 XmlAttribute 声明添加到现有 C# 类的成员

我正在尝试使用 XmlSerializer 的 Deserialize 方法将 XML 节点(从基本文本文件)反序列化为现有 C# 类的实例。反序列化失败...

回答 1 投票 0

通过 xmltodict 在 python 中解析 xml 文件

我正在 python 中使用 xmltodict 库(https://pypi.org/project/xmltodict/)来解析 xml 文件: 导入 xmltodict 将 open("MyXML.xml") 作为 MyXML: doc = xmltodict.parse(MyXML.read()) ...

回答 1 投票 0

如何用新值更新 XML 节点?

我的 App_Data 文件夹中有一个 xml。我需要编辑该 xml 节点中的值。我尝试过的是- XmlDocument xDoc = new XmlDocument(); xDoc.Load(Server.MapPath("~/App_D...

回答 4 投票 0

EditText 提示和文本的不同字体系列

我创建了一个包含多个 EditText 的布局,其中所有这些都是相同的字体系列。 其中一个 EditTexts 应该显示一个引用,并且一旦我...

回答 2 投票 0

如果存在yield,Python 会跳过递归

我有以下 XML 文件: 我有以下 XML 文件: <?xml version="1.0" encoding="UTF-8"?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:okp="okapi-framework:xliff-extensions" xmlns:its="http://www.w3.org/2005/11/its" xmlns:itsxlf="http://www.w3.org/ns/its-xliff/" its:version="2.0"> <file original="temp/file_conversion/tmp4a9kn6bn/69502fea-751c-4c3c-a38a-4fce9e13ebde.txt" source-language="en" target-language="ar" datatype="x-text/plain" okp:inputEncoding="UTF-8"> <body> <trans-unit id="1idhasofh" xml:space="preserve"> <source xml:lang="en">foo<bpt id="0">&lt;bar&gt;</bpt>&lt;Instruction><ept id="0">&lt;crow&gt;</ept>&lt;grande&gt;</source> <target xml:lang="ar">foo<bpt id="0">&lt;bar&gt;</bpt>&lt;Instruction><ept id="0">&lt;crow&gt;</ept>&lt;grande&gt;</target> </trans-unit> </body> </file> </xliff> 我正在尝试创建一个函数来解析我已读入 ElementTree.Element 的 XML 文件: from xml.etree import ElementTree as ET def parse_xml(ele: ET.Element): tag = ele.tag if not isinstance(tag, str) and tag is not None: return t = ele.text if t: yield t for e in ele: parse_xml(e) t = e.tail if t: yield t def main(): fp = "path/to/xml" tree = ET.parse(fp) root = tree.getroot() t_units = root.findall(".//{*}trans-unit") for source, target in t_units: for ele in parse_xml(source): print(ele) 我得到: foo <Instruction> <grande> 在我的调试器中,我看到 parse_xml(e) 被跳过。当我用打印语句替换产量时: def parse_xml(ele: ET.Element): tag = ele.tag if not isinstance(tag, str) and tag is not None: return t = ele.text if t: print(t) for e in ele: parse_xml(e) t = e.tail if t: print(t) 我得到了预期的结果(到达所有标记的文本): foo <bar> <Instruction> <crow> <grande> 为什么yield会出现这种情况? parse_xml 是一个生成器函数 - 当它被调用时,它不会运行:相反,它将返回一个必须迭代的生成器,就像对 parse_xml 的根调用在 for ele in parse_xml(source): 行中迭代一样在你的主要方法中。 此外, parse_xml 调用会立即返回生成器,而不在函数内运行任何代码 - 它是 for 语句,它实际上运行函数内的代码并将其前进到 yield 语句。 因此,您可以在每个递归 parse_xml 调用中循环返回值,如下所示: def parse_xml(ele: ET.Element): ... for e in ele: for inner_e in parse_xml(e): yield inner_e t = e.tail if t: yield t 或者,您可以使用 Python 的语法结构 yield from 来进行深层嵌套(或递归)生成器调用 - 这会更高效(并且对于使用其他功能的生成器还有其他优点,例如接受来自运行生成器的调用者函数)。这是推荐的方法: def parse_xml(ele: ET.Element): tag = ele.tag if not isinstance(tag, str) and tag is not None: return t = ele.text if t: yield t for e in ele: yield from parse_xml(e) t = e.tail if t: yield t yield from用于对parse_xml的内部调用的返回值,如此处将做“正确的事情”:推迟外部(当前)parse_xml调用的执行,并隧道内部调用产生的每个值到它的调用者 - 当内部调用结束时(它产生一个 StopIteration:与创建 for 循环相同的机制stop),外部调用的执行将恢复。

回答 1 投票 0

java swing 库,其布局在 XML 中定义

是否有一个 Swing 库可以从 XMl 文件获取其布局?

回答 5 投票 0

Odoo 16 系统中未找到外部 ID:website.assets_frontend

我对 Odoo 有点陌生,我想制作自己的 odoo 模块片段。但是当我尝试激活我的代码片段时,我收到此错误: RPC_错误 Odoo 服务器错误 回溯(最近一次调用最后一次): ...

回答 1 投票 0

从以 XML 格式存储的 UML 模型中提取类和关系

我目前正在使用不同的 UML/SysML 模型,并将其导出到 xml 文件中。我在文档中有不同的对象和关系,我想用 python 对它们进行聚类。哪个是

回答 1 投票 0

XSLT 转换:使用 XSLT 1.0 来使用位置和当前

这是输入 XML: A47422 A47423 这是输入 XML: <deliveryStatusRequest> <Partner> <partyRoleId>A47422</partyRoleId> <Banner> <partyRoleId>A47423</partyRoleId> <POS> <partyRoleId>A47424</partyRoleId> </POS> <POS> <partyRoleId>A47425</partyRoleId> </POS> </Banner> <Banner> <partyRoleId>A47426</partyRoleId> <POS> <partyRoleId>A47428</partyRoleId> </POS> </Banner> </Partner> <ProcessData> <Partner> <returnCode>00</returnCode> <returnDescription>123456789</returnDescription> <Banner> <returnCode>00</returnCode> <returnDescription>234567890</returnDescription> <POS> <returnCode>01</returnCode> <returnDescription>Some error</returnDescription> </POS> <POS> <returnCode>00</returnCode> <returnDescription>456789012</returnDescription> </POS> </Banner> <Banner> <returnCode>00</returnCode> <returnDescription>567890123</returnDescription> <POS> <returnCode>02</returnCode> <returnDescription>Some Error</returnDescription> </POS> </Banner> </Partner> </ProcessData> </deliveryStatusRequest> 这是预期的输出: <SiebelMessage MessageType="Integration Object" IntObjectName="SFA Create Update Seller IO" IntObjectFormat="Siebel Hierarchical"> <ListOfSfaCreateUpdateSellerIo> <SfaSubAccountmasterBc> <CodiceSFA/> <!--Mapped to PartyRowId--> <CodiceSAP> <!--Mapped to returnDescription if returnCode is 00--> <StatoSAP> <!--"Attivo" If returnCode is 00 --> <StatoCommerciale> <!-- "Attivo" If returnCode is 00 else set to "Prospect"--> <DescrizioneRitornoSAP> <!--Mapped to returnDescription if returnCode is not 00--> <ListOfSfaSubaccountInsegnaBc> <SfaSubaccountInsegnaBc> <CodiceSFA/> <!--Mapped to PartyRowId--> <CodiceSAP> <!--Mapped to returnDescription if returnCode is 00--> <StatoSAP> <!--"Attivo" If returnCode is 00 --> <StatoCommerciale> <!-- "Attivo" If returnCode is 00 else set to "Prospect"--> <DescrizioneRitornoSAP> <!--Mapped to returnDescription if returnCode is not 00--> <ListOfSfaSubaccountPdvBc> <SfaSubaccountPdvBc> <CodiceSFA/> <!--Mapped to PartyRowId--> <CodiceSAP> <!--Mapped to returnDescription if returnCode is 00-- <StatoSAP> <!--"Attivo" If returnCode is 00 --> <StatoCommerciale> <!-- "Attivo" If returnCode is 00 else set to "Prospect"--> <DescrizioneRitornoSAP> <!--Mapped to returnDescription if returnCode is not 00--> </SfaSubaccountPdvBc> </ListOfSfaSubaccountPdvBc> </SfaSubaccountInsegnaBc> </ListOfSfaSubaccountInsegnaBc> </SfaSubAccountmasterBc> </ListOfSfaCreateUpdateSellerIo> </SiebelMessage> 我创建了 XSLT,但它不起作用: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:template match="deliveryStatusRequest"> <SiebelMessage MessageType="Integration Object" IntObjectName="SFA Create Update Seller IO" IntObjectFormat="Siebel Hierarchical"> <ListOfSfaCreateUpdateSellerIo> <xsl:apply-templates select="Partner"/> </ListOfSfaCreateUpdateSellerIo> </SiebelMessage> </xsl:template> <xsl:template match="Partner"> <SfaSubAccountmasterBc> <CodiceSFA> <xsl:value-of select="partyRoleId"/> </CodiceSFA> <CodiceSAP> <xsl:choose> <xsl:when test="../ProcessData/Partner/returnCode = '00'"> <xsl:value-of select="../ProcessData/Partner/returnDescription"/> </xsl:when> </xsl:choose> </CodiceSAP> <StatoSAP>Attivo</StatoSAP> <StatoCommerciale>Attivo</StatoCommerciale> <DescrizioneRitornoSAP/> <ListOfSfaSubaccountInsegnaBc> <xsl:apply-templates select="Banner"/> </ListOfSfaSubaccountInsegnaBc> </SfaSubAccountmasterBc> </xsl:template> <xsl:template match="Banner"> <SfaSubaccountInsegnaBc> <CodiceSFA> <xsl:value-of select="partyRoleId"/> </CodiceSFA> <CodiceSAP> <xsl:choose> <xsl:when test="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnCode = '00'"> <xsl:value-of select="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnDescription"/> </xsl:when> </xsl:choose> </CodiceSAP> <StatoSAP>Attivo</StatoSAP> <StatoCommerciale>Attivo</StatoCommerciale> <DescrizioneRitornoSAP> <xsl:choose> <xsl:when test="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnCode != '00'"> <xsl:value-of select="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnDescription"/> </xsl:when> </xsl:choose> </DescrizioneRitornoSAP> <ListOfSfaSubaccountPdvBc> <xsl:apply-templates select="POS"/> </ListOfSfaSubaccountPdvBc> </SfaSubaccountInsegnaBc> </xsl:template> <xsl:template match="POS"> <SfaSubaccountPdvBc> <CodiceSFA> <xsl:value-of select="partyRoleId"/> </CodiceSFA> <CodiceSAP> <xsl:choose> <xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode = '00'"> <xsl:value-of select="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnDescription"/> </xsl:when> </xsl:choose> </CodiceSAP> <StatoSAP> <xsl:choose> <xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode = '00'">Attivo</xsl:when> </xsl:choose> </StatoSAP> <StatoCommerciale> <xsl:choose> <xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode = '00'">Attivo</xsl:when> <xsl:otherwise>Prospect</xsl:otherwise> </xsl:choose> </StatoCommerciale> <DescrizioneRitornoSAP> <xsl:choose> <xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode != '00'"> <xsl:value-of select="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnDescription"/> </xsl:when> </xsl:choose> </DescrizioneRitornoSAP> </SfaSubaccountPdvBc> </xsl:template> </xsl:stylesheet> 我得到这样的输出,codiceSAP 没有填充所有实体: <?xml version="1.0"?> <SiebelMessage MessageType="Integration Object" IntObjectName="SFA Create Update Seller IO" IntObjectFormat="Siebel Hierarchical"> <ListOfSfaCreateUpdateSellerIo> <SfaSubAccountmasterBc> <CodiceSFA>A47422</CodiceSFA> <CodiceSAP>123456789</CodiceSAP> <StatoSAP>Attivo</StatoSAP> <StatoCommerciale>Attivo</StatoCommerciale> <DescrizioneRitornoSAP/> <ListOfSfaSubaccountInsegnaBc> <SfaSubaccountInsegnaBc> <CodiceSFA>A47423</CodiceSFA> <CodiceSAP/> <StatoSAP>Attivo</StatoSAP> <StatoCommerciale>Attivo</StatoCommerciale> <DescrizioneRitornoSAP/> <ListOfSfaSubaccountPdvBc> <SfaSubaccountPdvBc> <CodiceSFA>A47424</CodiceSFA> <CodiceSAP/> <StatoSAP>Prospect</StatoSAP> <StatoCommerciale/> <DescrizioneRitornoSAP/> </SfaSubaccountPdvBc> <SfaSubaccountPdvBc> <CodiceSFA>A47425</CodiceSFA> <CodiceSAP/> <StatoSAP>Prospect</StatoSAP> <StatoCommerciale/> <DescrizioneRitornoSAP/> </SfaSubaccountPdvBc> </ListOfSfaSubaccountPdvBc> </SfaSubaccountInsegnaBc> <SfaSubaccountInsegnaBc> <CodiceSFA>A47426</CodiceSFA> <CodiceSAP/> <StatoSAP>Attivo</StatoSAP> <StatoCommerciale>Attivo</StatoCommerciale> <DescrizioneRitornoSAP/> <ListOfSfaSubaccountPdvBc> <SfaSubaccountPdvBc> <CodiceSFA>A47428</CodiceSFA> <CodiceSAP/> <StatoSAP>Prospect</StatoSAP> <StatoCommerciale/> <DescrizioneRitornoSAP/> </SfaSubaccountPdvBc> </ListOfSfaSubaccountPdvBc> </SfaSubaccountInsegnaBc> </ListOfSfaSubaccountInsegnaBc> </SfaSubAccountmasterBc> </ListOfSfaCreateUpdateSellerIo> </SiebelMessage> 逻辑是这样的: CodiceSAP for POS:如果 returnCode = '00',则填充 CodiceSAP。 POS 的 RitornoSAP 描述:仅当 returnCode != '00' 时才填充。 StatoSAP 和 StatoCommerciale for POS:当 returnCode = '00' 时设置为 Attivo;否则,默认“” (StatoSAP) 和“Prospect”(对于 StatoCommerciale)。 我认为您需要向上移动一级..才能填充CodiceSAP,例如 <xsl:template match="Banner"> <SfaSubaccountInsegnaBc> <CodiceSFA> <xsl:value-of select="partyRoleId"/> </CodiceSFA> <CodiceSAP> <xsl:choose> <xsl:when test="../../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnCode = '00'"> <xsl:value-of select="../../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnDescription"/> </xsl:when> </xsl:choose> </CodiceSAP>

回答 1 投票 0

XML-RPC ping(谷歌和其他)

我正在尝试在 PHP 中 ping(称为“ping”的 SEO 策略用于新内容,以使机器人更快地对其进行索引)Google。我唯一知道的是我需要将请求发送到以下网址: http://博客...

回答 4 投票 0

如何覆盖WPF中MenuItem的默认颜色?

我想覆盖WPF中MenuItem的默认颜色,但我的方法似乎没有按预期工作。我想更改 MenuItem 的默认颜色,例如 MenuItem.Selected.Background、Menu...

回答 1 投票 0

Haskell:树上的箭头、XML 和 Hxt:将文本叶子转换为子树

背景 Freeplane 应用程序似乎已经消亡了数十年。我正在从中提取我的数据。 Freeplane 将数据存储为 XML。我采取的首要步骤之一就是统一该格式。

回答 1 投票 0

如何使用 Jackson Mapper 将 Map 字段序列化为 xml 属性

我有数据课 类数据项{ 私有字符串名称; 私有地图参数; // 获取器、设置器 } 我可以轻松地用杰克逊将其序列化,如下所示 ...

回答 1 投票 0

如何在XML中只获取特定节点及其属性的信息

我有一个 .xml 文件,其中包含角色的信息。我正在尝试获取节点和属性的名称和值。我尝试过使用 XmlReader,但它不起作用,我也没有......

回答 1 投票 0

以与HXT一致的方式解析外部文档和当前元素

更新:我现在已经解决了我的主要问题,因此我将奖励对我的解决方案是否良好风格的良好审查。 最近我一直在尝试解析TMX文件,这些文件是描述...的XML文件

回答 1 投票 0

HXT:输入可以用箭头语法改变吗?

用以下代码 {-# 语言箭头#-} {-# LANGUAGE NoMonomorphismRestriction #-} 导入文本.XML.HXT.Core parseXml :: IOSArrow XmlTree XmlTree parseXml = getChildren >>> getChi...

回答 2 投票 0

android 工具栏在 api 35 中无法正常工作

我有一个在所有设备上都能很好地工作的应用程序,但我最近将目标 sdk 更新到了 api 35,现在我的应用程序的工具栏在 android api 35 中中断,并且在 ap 之前的所有其他设备上都能正常工作...

回答 1 投票 0

如何在 XSLT 中引用包含嵌套 XML 的变量

我想引用我在 XSLT 文件中定义的变量的更深 XML 级别。但是,当我尝试使用 XSLT 转换 XSD 时,它总是说我的样式表无效。只有当...

回答 1 投票 0

在 SOAP 消息中显示传输级别信息错误

我正在尝试在 wso2 中消费后使用类中介器处理消息。但是,出现以下错误: 传输级别信息与 SOAP 消息命名空间 URI 不匹配 谁都可以吗

回答 1 投票 0

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