我有一个这样的 XML:
<request type="POST">
<paths count="0"/>
<values count="9">
<Invoices1>123ABC</Invoices1>
<Invoices2>456EFG</Invoices2>
<Invoices3>789HIJ</Invoices3>
<Invoices4>012KLM</Invoices4>
<case_Email>Email</case_Email>
<case_Print>case_Print</case_Print>
<case_Fax>Fax</case_Fax>
<zone_TexteReponse>jkg</zone_TexteReponse>
<Editer>Editer</Editer>
</values>
Run Code Online (Sandbox Code Playgroud)
我会使用 XSL 来转换此 XML,但我正在努力处理标签 Invoicexxx。我如何使用 XPath 选择它们:
/request/values/Invoices*
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助 :-)
/request/values/*[starts-with(name(), 'Invoices')]
Run Code Online (Sandbox Code Playgroud)
这是一个很好的例子,说明了如何不使用 XML。该 XML 应该如下所示:
<request type="POST">
<paths />
<values>
<Invoice>123ABC</Invoice>
<Invoice>456EFG</Invoice>
<Invoice>789HIJ</Invoice>
<Invoice>012KLM</Invoice>
<case>
<Email>Email</Email>
<Print>Print</Print>
<Fax>Fax</Fax>
</case>
<zone>
<TexteReponse>jkg</TexteReponse>
</zone>
<Editer>Editer</Editer>
</values>
</request>
Run Code Online (Sandbox Code Playgroud)
现在更明智的/request/values/Invoice做法会起作用。
使用 XML 应避免的事情
<Invoice>XML 中的第二张发票。<case_Email>.<values count="9">都是多余的。如果你想数孩子们,就数他们吧。绝对不需要在任何地方存储计数。