无法访问XML中的子节点

时间:2013-09-26 22:20:44

标签: xml web-services soap coldfusion

我正在使用Coldfusion 9创建一个SOAP Web服务,以允许我们的销售合作伙伴直接将订单发布到我们的电子商务平台。入站SOAP消息包含如下所示的节点:

...
<LineItem xsi:type="ws1:Item">
   <LineNumber xsi:type="xsd:double">1</LineNumber>
    <PartNumber xsi:type="xsd:string">Widget-01</PartNumber>
    <Price xsi:type="xsd:double">100</Price>
    <Quantity xsi:type="xsd:double">4</Quantity>
    <SubscriberEmail xsi:type="xsd:string">nitwit@gmail.com</SubscriberEmail>
    <UnitofMeasure xsi:type="xsd:string">EA</UnitofMeasure>
</LineItem>
...

我收到带有以下Coldfusion代码的入站请求:

<cfset theXML = getsoaprequest() />

<cfset arrNodes = XmlSearch(theXML, "//LineItem") />

<cfset rtn = arrNodes[1].PartNumber.XmlText/>

但是第三行引发了一个错误:“元素PARTNUMBER.XMLTEXT在类型为coldfusion.xml.XmlNodeMap的Java对象中未定义,引用为''”

当我将第三行更改为:arrNodes[1].XmlChildren时,它不会返回任何结果。它几乎就像子节点不存在一样,但arrNodes[1]返回一个完全填充的节点。

我错过了什么?

编辑:这是整个SoapBody:

   <soapenv:Body>
  <ws1:createOrder soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <Order xsi:type="ws1:Order">
        <BillToAddress xsi:type="ws1:Address">
           <AddrLine1 xsi:type="xsd:string">10101 Main Street</AddrLine1>
           <AddrLine2 xsi:type="xsd:string">Science Lab</AddrLine2>
           <AddrLine3 xsi:type="xsd:string"></AddrLine3>
           <Attention xsi:type="xsd:string">John Doe</Attention>
           <AttnPhone xsi:type="xsd:string">877-555-0131</AttnPhone>
           <City xsi:type="xsd:string">Roseville</City>
           <CompanyName xsi:type="xsd:string">Washington High School</CompanyName>
           <Country xsi:type="xsd:string">USA</Country>
           <PostalCode xsi:type="xsd:string">95747</PostalCode>
           <StateProvince xsi:type="xsd:string">CA</StateProvince>
        </BillToAddress>
        <CustPO xsi:type="xsd:string">asdfasdf13241234</CustPO>
        <OrderDate xsi:type="xsd:dateTime">2002-05-30T09:00:00</OrderDate>
        <OrderDetail xsi:type="ws1:Orderdetail">
           <LineItem xsi:type="ws1:Item">
              <LineNumber xsi:type="xsd:double">1</LineNumber>
              <PartNumber xsi:type="xsd:string">Widget01</PartNumber>
              <Price xsi:type="xsd:double">100</Price>
              <Quantity xsi:type="xsd:double">4</Quantity>
              <SubscriberEmail xsi:type="xsd:string">nitwit@gmail.com</SubscriberEmail>
              <UnitofMeasure xsi:type="xsd:string">EA</UnitofMeasure>
           </LineItem>
           <LineItem xsi:type="ws1:Item">
              <LineNumber xsi:type="xsd:double">2</LineNumber>
              <PartNumber xsi:type="xsd:string">>Widget02</PartNumber>
              <Price xsi:type="xsd:double">100</Price>
              <Quantity xsi:type="xsd:double">6</Quantity>
              <SubscriberEmail xsi:type="xsd:string">nitwit@gmail.com</SubscriberEmail>
              <UnitofMeasure xsi:type="xsd:string">EA</UnitofMeasure>
           </LineItem>
        </OrderDetail>
        <PurchAgent xsi:type="xsd:string">Mary</PurchAgent>
        <PurchAgentEmail xsi:type="xsd:string">mary@gmail.com</PurchAgentEmail>
        <PurchAgentPhone xsi:type="xsd:string">877-555-0131</PurchAgentPhone>
        <ShipToAddress xsi:type="ws1:Address">
           <AddrLine1 xsi:type="xsd:string">10101 Main Street</AddrLine1>
           <AddrLine2 xsi:type="xsd:string">Science Lab</AddrLine2>
           <AddrLine3 xsi:type="xsd:string"></AddrLine3>
           <Attention xsi:type="xsd:string">John Doe</Attention>
           <AttnPhone xsi:type="xsd:string">877-555-0131</AttnPhone>
           <City xsi:type="xsd:string">Roseville</City>
           <CompanyName xsi:type="xsd:string">Washington High School</CompanyName>
           <Country xsi:type="xsd:string">USA</Country>
           <PostalCode xsi:type="xsd:string">95747</PostalCode>
           <StateProvince xsi:type="xsd:string">CA</StateProvince>
        </ShipToAddress>
        <SoldToAddress xsi:type="ws1:Address">
           <AddrLine1 xsi:type="xsd:string">10101 Main Street</AddrLine1>
           <AddrLine2 xsi:type="xsd:string">Science Lab</AddrLine2>
           <AddrLine3 xsi:type="xsd:string"></AddrLine3>
           <Attention xsi:type="xsd:string">John Doe</Attention>
           <AttnPhone xsi:type="xsd:string">877-555-0131</AttnPhone>
           <City xsi:type="xsd:string">Roseville</City>
           <CompanyName xsi:type="xsd:string">Washington High School</CompanyName>
           <Country xsi:type="xsd:string">USA</Country>
           <PostalCode xsi:type="xsd:string">95747</PostalCode>
           <StateProvince xsi:type="xsd:string">CA</StateProvince>
        </SoldToAddress>
     </Order>
  </ws1:createOrder>

编辑:这是我添加的代码(在Scott的建议下),它使其工作:

<cfset strXML = ToString(docXML) />     
    <cfset strXml = REReplace( strXml, "^[^<]*", "", "all" ) />         
    <cfset docXML = XMLParse(strXML) />

0 个答案:

没有答案