代码之家  ›  专栏  ›  技术社区  ›  Mike

在另一个字段的特定条件下获取XML字段值-最快的方法

  •  0
  • Mike  · 技术社区  · 6 年前

    有很多方法。但我只是想知道是否有一种更快的方法(考虑到开发时间)或api可以在其他字段的特定条件上检索指定字段的值。

    也就是说,假设我有这个XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
          <port:getAllIdentificationsResponse xmlns:port="http://www.ibm.com/Party">
             <ResponseControl xmlns="http://www.ibm.com/schema">
                <ResultCode>SUCCESS</ResultCode>
                <ServiceTime>8</ServiceTime>
             </ResponseControl>
             <PartyIdentificationBObj>
                <IdentificationIdPK>1234</IdentificationIdPK>
                <IdentificationValue>DRIVER LICENSE</IdentificationValue>
                <IdentificationNumber>5678</IdentificationNumber>
                <PartyIdentificationLastUpdateUser>EVERGREEN</PartyIdentificationLastUpdateUser>
                <PartyIdentificationLastUpdateTxId>7777</PartyIdentificationLastUpdateTxId>
             </TCRMPartyIdentificationBObj>
             <PartyIdentificationBObj>
                <IdentificationIdPK>2345</IdentificationIdPK>
                <IdentificationValue>SOURCE IDENTIFIER</IdentificationValue>
                <IdentificationNumber>429043825</IdentificationNumber>
                <PartyIdentificationLastUpdateUser>EVERGREEN</PartyIdentificationLastUpdateUser>
                <PartyIdentificationLastUpdateTxId>8888</PartyIdentificationLastUpdateTxId>
             </TCRMPartyIdentificationBObj>
             <PartyIdentificationBObj>
                <IdentificationIdPK>3456</IdentificationIdPK>
                <PartyId>249443337882014002</PartyId>
                <IdentificationType>300</IdentificationType>
                <IdentificationValue>MEMBERSHIP NUMBER</IdentificationValue>
                <IdentificationNumber>429043825</IdentificationNumber>
                <PartyIdentificationLastUpdateUser>EVERGREEN</PartyIdentificationLastUpdateUser>
                <PartyIdentificationLastUpdateTxId>9999</PartyIdentificationLastUpdateTxId>
             </TCRMPartyIdentificationBObj>
             <PartyIdentificationBObj>
                <IdentificationIdPK>4567</IdentificationIdPK>
                <IdentificationValue>SOURCE IDENTIFIER</IdentificationValue>
                <IdentificationNumber>UTS~^~3229004~^~1</IdentificationNumber>
                <PartyIdentificationLastUpdateUser>EVERGREEN</PartyIdentificationLastUpdateUser>
                <PartyIdentificationLastUpdateTxId>1111</PartyIdentificationLastUpdateTxId>
             </TCRMPartyIdentificationBObj>
          </port:getAllIdentificationsResponse>
       </soapenv:Body>
    </soapenv:Envelope>
    

    我想把 识别号 所有领域 识别值 源标识符 ?

    我的结果应该是 429043825 , UTS~^~322904~^~1 .

    一个关于怎样做才是最好的建议会更有帮助。

    1 回复  |  直到 6 年前
        1
  •  1
  •   kjhughes    6 年前

    最快的是没有意义的具体为谁和由什么。开发时间或处理速度最快?如果要进行处理,这几乎肯定无关紧要,但您必须针对特定的软件和硬件环境进行测量。

    省去(可能)不必要的担心,只需使用xpath…

    这个xpath,

    //PartyIdentificationBObj[IdentificationValue='SOURCE IDENTIFIER']/IdentificationNumber
    

    将全部返回 IdentificationNumber 元素子元素 PartyIdentificationBObj 带子元素的元素 IdentificationValue "SOURCE IDENTIFIER" ,根据要求。