2014-11-12 10 views
1

Учитывая следующий XML:XPath терпит неудачу при использовании XmlUtil (UFT) 12,0

<?xml version="1.0" encoding="UTF-8" ?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Header> 
    <WFContext xmlns="http://service.wellsfargo.com/entity/message/2003/" soapenv:actor="" soapenv:mustUnderstand="0"> 
     <messageId>cci-sf-dev14.wellsfargo.com:425a9286:14998ac6245:-7e1e</messageId> 
     <sessionId>425a9286:14998ac6245:-7e1d</sessionId> 
     <sessionSequenceNumber>1</sessionSequenceNumber> 
     <creationTimestamp>2014-11-10T00:14:49.243-08:00</creationTimestamp> 
     <invokerId>cci-sf-dev14.wellsfargo.com</invokerId> 
     <activitySourceId>P7</activitySourceId> 
     <activitySourceIdType>FNC</activitySourceIdType> 
     <hostName>cci-sf-dev14.wellsfargo.com</hostName> 
     <billingAU>05426</billingAU> 
     <originatorId>287586861901211</originatorId> 
     <originatorIdType>ECN</originatorIdType> 
     <initiatorId>GTST0793</initiatorId> 
     <initiatorIdType>ACF2</initiatorIdType> 
    </WFContext> 
    </soapenv:Header> 
    <soapenv:Body> 
    <getCustomerInformation xmlns="http://service.wellsfargo.com/provider/ecpr/customerProfile/inquiry/getCustomerInformation/2012/05/"> 
     <initiatorInformation xmlns="http://service.wellsfargo.com/provider/ecpr/shared/common/2011/11/"> 
     <channelInfo> 
      <initiatorCompanyNbr xmlns="http://service.wellsfargo.com/entity/message/2003/">114</initiatorCompanyNbr> 
     </channelInfo> 
     </initiatorInformation> 
     <custNbr xmlns="http://service.wellsfargo.com/entity/party/2003/">287586861901211</custNbr> 
     <customerViewList xmlns="http://service.wellsfargo.com/provider/ecpr/customerProfile/inquiry/getCustomerInformationCommon/2012/05/"> 
     <customerView> 
      <customerViewType>GENERAL_INFORMATION_201205</customerViewType> 
      <preferences> 
      <generalInformationPreferences201205 xmlns="http://service.wellsfargo.com/provider/ecpr/customerProfile/inquiry/common/2012/05/"> 
       <formattedNameIndicator xmlns="">true</formattedNameIndicator> 
       <includeTaxCertificationIndicator xmlns="">true</includeTaxCertificationIndicator> 
      </generalInformationPreferences201205> 
      </preferences> 
     </customerView> 
     <customerView> 
      <customerViewType>SEGMENT_LIST</customerViewType> 
     </customerView> 
     <customerView> 
      <customerViewType>LIMITED_PROFILE_REQUIRED_DATA</customerViewType> 
     </customerView> 
     <customerView> 
      <customerViewType>INDIVIDUAL_CUSTOMER_GENERAL_INFORMATION_201205</customerViewType> 
     <preferences> 
      <individualGeneralInformationPreferences xmlns="http://service.wellsfargo.com/provider/ecpr/customerProfile/inquiry/common/2012/05/"> 
      <includeMinorIndicator xmlns="">true</includeMinorIndicator> 
      </individualGeneralInformationPreferences> 
     </preferences> 
     </customerView> 
     </customerViewList> 
    </getCustomerInformation> 
    </soapenv:Body> 
</soapenv:Envelope> 

Я пытаюсь получить доступ к getCustomerInformation метку, используя относительную XPath в VBScript.

XMLDataFile = "C:\testReqfile.xml" 
Set xmlDoc = XMLUtil.CreateXML() 
xmlDoc.LoadFile(XMLDataFile) 
Print xmlDoc.ToString 
'xmlDoc.AddNamespace "ns","xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/" 
Set childrenObj = xmlDoc.ChildElementsByPath("//*[contains(@xmlns,'getCustomerInformation')]") 
msgbox childrenObj.Count 

Но не удается вернуть узел.

ответ

1

Ваше выражение XPath не работает, потому что xmlns как в

<getCustomerInformation xmlns="http://service.wellsfargo.com/provider/ecpr/customerProfile/inquiry/getCustomerInformation/2012/05/"> 

имен по умолчанию , не является атрибутом. Поэтому к нему нельзя получить доступ с помощью @xmlns.

Но, похоже, вам вообще не нужно полагаться на пространство имен, потому что имя элемента («информация о получателе») уже сказано. Чтобы обойти проблему тех элементов, которые находятся в пространстве имен, используйте local-name() для выбора элементов по их имени.

Set childrenObj = xmlDoc.ChildElementsByPath("//*[local-name() = 'getCustomerInformation']") 
0

Как @Mathias Müller уже объяснил в своем ответе, xmlns определяет пространство имен и, таким образом, не может быть доступен как обычный атрибут. У меня нет опыта работы с XmlUtil, но в стандартном VBScript вы можете выбрать такие узлы:

Set xml = CreateObject("Msxml2.DOMDocument.6.0") 
xml.async = False 
xml.load "C:\path\to\your.xml" 

If xml.ParseError Then 
    WScript.Echo xml.ParseError.Reason 
    WScript.Quit 1 
End If 

'define a namespace alias "ns" 
uri = "http://service.wellsfargo.com/provider/ecpr/customerProfile/inquiry/getCustomerInformation/2012/05/" 
xml.setProperty "SelectionNamespaces", "xmlns:ns='" & uri & "'" 

'select nodes using the namespace alias 
Set nodes = xml.SelectNodes("//ns:getCustomerInformation") 
Смежные вопросы