Php XML响应-访问某些字段
这是我的XML响应,我需要通过PHPPhp XML响应-访问某些字段,php,xml,soap,Php,Xml,Soap,这是我的XML响应,我需要通过PHP64846访问它,我如何选择该数字并将其用作变量 非常感谢 $value = get_field( "VehicleCode" ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "htt
64846
访问它,我如何选择该数字并将其用作变量
非常感谢
$value = get_field( "VehicleCode" );
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://soap.cap.co.uk/Vehicles/CapVehicles.asmx/GetCapidFromCapcode?subscriberId=***&password=**&database=CAR&caPcode=$value",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Host: soap.cap.co.uk",
"Postman-Token: d47f0fcb-93a6-4c0d-bf5f-7feb3ecbc2f3,662c8fc9-d1ff-4dfc-8063-0c281f78d2d8",
"User-Agent: PostmanRuntime/7.19.0",
"cache-control: no-cache"
),
));
$xml = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$dom=new DOMDocument;
$dom->loadXML( $xml ); # where $xml is the soap response XML string
$cder=$dom->getElementsByTagName('CDer_ID')[0];
echo $cder->nodeValue;
My Response
<?xml version="1.0" encoding="utf-8"?>
<CAPDataSetResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://soap.cap.co.uk/vehicles">
<Success>true</Success>
<FailMessage />
<Returned_DataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="CDer_ID" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<CDer_ID>64846</CDer_ID>
</Table>
</NewDataSet>
</diffgr:diffgram>
</Returned_DataSet>
</CAPDataSetResult>
$value=get_字段(“车辆代码”);
$curl=curl_init();
curl_setopt_数组($curl,数组(
CURLOPT_URL=>”https://soap.cap.co.uk/Vehicles/CapVehicles.asmx/GetCapidFromCapcode?subscriberId=***&密码=**&database=CAR&caPcode=$value“,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_编码=>“”,
CURLOPT_MAXREDIRS=>10,
CULLOPT_超时=>30,
CURLOPT_HTTP_VERSION=>CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST=>“获取”,
CURLOPT_HTTPHEADER=>数组(
“接受:*/*”,
“接受编码:gzip,deflate”,
“缓存控制:无缓存”,
“连接:保持活动状态”,
“主持人:soap.cap.co.uk”,
“邮递员代币:d47f0fcb-93a6-4c0d-bf5f-7FEB3ECBC2F3662C8FC9-d1ff-4dfc-8063-0c281f78d2d8”,
“用户代理:PostmanRuntime/7.19.0”,
“缓存控制:无缓存”
),
));
$xml=curl\u exec($curl);
$err=curl\u error($curl);
curl_close($curl);
$dom=新的DOMDocument;
$dom->loadXML($xml);#其中,$xml是soap响应xml字符串
$cder=$dom->getElementsByTagName('cder_ID')[0];
echo$cder->nodeValue;
我的回答
真的
64846
以最简单的形式访问标记的值CDer\u ID
您可以执行以下操作:
$dom=new DOMDocument;
$dom->loadXML( $xml ); # where $xml is the soap response XML string
$cder=$dom->getElementsByTagName('CDer_ID')[0];
echo $cder->nodeValue;
以访问标记值的最简单形式
CDer\u ID
可以执行以下操作:
$dom=new DOMDocument;
$dom->loadXML( $xml ); # where $xml is the soap response XML string
$cder=$dom->getElementsByTagName('CDer_ID')[0];
echo $cder->nodeValue;
您还没有共享一点PHP代码。您需要帮助处理SOAP例程的哪一部分?抱歉不确定是否需要我共享呼叫,我已共享了上面的呼叫。抱歉,我被标签弄糊涂了。我以为你在用。你基本上只是在问如何用一般术语解析XML,对吗?我认为这是一个重复:看看这样的东西应该适合你:($xmlString=preg_replace(“/(]*>)/”,“$1$2$3”,$xmlString);$XML=new simplexmlement($xmlString);var_dump($XML);)基本上是的。感谢您的回复。您还没有共享一点PHP代码。您需要帮助处理SOAP例程的哪一部分?抱歉不确定是否需要我共享呼叫,我已共享了上面的呼叫。抱歉,我被标签弄糊涂了。我以为你在用。你基本上只是在问如何用一般术语解析XML,对吗?我认为这是一个重复:看看这样的东西应该适合你:($xmlString=preg_replace(“/(]*>)/”,“$1$2$3”,$xmlString);$XML=new simplexmlement($xmlString);var_dump($XML);)基本上是的。谢谢你的回复。像这样吗?我现在似乎没有得到任何输出。我做错了什么?非常感谢您花时间回复。您上面使用的看起来是正确的-假设变量
$xml
在curl请求之后正确填充,那么一切正常吗?像这样?我现在似乎没有得到任何输出。我做错了什么?非常感谢您花时间回复。您上面使用的看起来是正确的-假设变量$xml
在curl请求之后正确填充,那么一切正常吗?