【问题标题】:coldfusion/xml - obtain a value by xmlName, rather than by xmlchildren array positionColdfusion/xml - 通过 xmlName 获取值,而不是通过 xmlchildren 数组位置
【发布时间】:2012-05-15 00:49:10
【问题描述】:

给定以下 XML“thisXML”:

我可以通过

获取产品名称
<cfset vProduct = thisXML.xmlchildren[1].xmltext>

但是,如何通过 xmlName 获取值,而不是通过 xmlChildren 数组位置,即在伪代码中:

<cfset vProduct = thisXML.xmlchildren[xmlName='product'].xmltext>

【问题讨论】:

  • 查看 XPath 和 XMLSearch

标签: xml coldfusion


【解决方案1】:

您应该可以通过 thisXML.Product 获得它 - 它对我有用。

--xmltest.xml

<table1>
    <product>KiaOra</product>
    <SubscriberCode>2232481600</SubscriberCode>
</table1>

--xmltest.cfm

<cfscript>
    // this is setup stuff
    f = FileRead(expandPath("xmltest.xml"));
    x = XmlParse(f);
    xDetail = XmlSearch(x,"/table1")[1]; // this gets the exact result your cfdump image has

    // here is the important part
    writeOutput(xDetail.product.xmlText);
</cfscript>

--输出

KiaOra

您只需要意识到,即使您的 XML 在详细视图中打印出来,它仍然像标准 cfdump 视图中的 XML 一样工作。

【讨论】:

    猜你喜欢
    • 2021-01-17
    • 2017-08-27
    • 2014-06-11
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多