为了账号安全,请及时绑定邮箱和手机立即绑定

使用具有多个名称空间的SimpleXML解析XML

使用具有多个名称空间的SimpleXML解析XML

PHP
汪汪一只猫 2019-10-12 10:20:46
我有一个丑陋的XML,上面有很多名称空间,当我尝试通过simpleXML加载它(如果我指示第一个名称空间)时,我会得到一个xml对象,但是后面带有其他名称空间的标记不会使它成为该对象。如何解析该XML?<?xml version="1.0" encoding="UTF-8"?><soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">    <soap-env:Header>        <eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">            <eb:From>                <eb:PartyId eb:type="URI">wscompany.com</eb:PartyId>            </eb:From>            <eb:To>                <eb:PartyId eb:type="URI">mysite.com</eb:PartyId>            </eb:To>            <eb:CPAId>something</eb:CPAId>            <eb:ConversationId>moredata.com</eb:ConversationId>            <eb:Service eb:type="compXML">theservice</eb:Service>            <eb:Action>theaction</eb:Action>            <eb:MessageData>                <eb:MessageId>a certain messageid</eb:MessageId>                <eb:Timestamp>2009-04-11T18:43:58</eb:Timestamp>                <eb:RefToMessageId>mid:areference</eb:RefToMessageId>            </eb:MessageData>        </eb:MessageHeader>        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">            <wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">an impresive binary security toekn</wsse:BinarySecurityToken>        </wsse:Security>    </soap-env:Header>    <soap-env:Body>        <SessionCreateRS xmlns="http://www.opentravel.org/OTA/2002/11" version="1" status="Approved">            <ConversationId>the goodbye token</ConversationId>        </SessionCreateRS>    </soap-env:Body></soap-env:Envelope>我试图用下面的代码解析它<?php$xml = simplexml_load_string($res,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");?>但是$ xml对象仅包含以下内容SimpleXMLElement Object(    [Header] => SimpleXMLElement Object        (        )    [Body] => SimpleXMLElement Object        (        ))
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 402 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信