Php 如何使用simplexml\u load\u字符串读取XML标记的值
如何读取指令标记“DO IT”的值Php 如何使用simplexml\u load\u字符串读取XML标记的值,php,xml,Php,Xml,如何读取指令标记“DO IT”的值 如何提取=>使用正确关闭的标记为您的blob提取=>DoIt: $XML_BLOB = ' <Rate maxRate="HIGH" Type="PROD" situs="DESTINATION" inputOutputType="OUTPUT" FromParty="BUYER"> <Instruction instructionLevel="DESIGN" instructionId="1234">DO IT
如何提取=>使用正确关闭的
标记为您的blob提取=>DoIt:
$XML_BLOB = '
<Rate maxRate="HIGH" Type="PROD" situs="DESTINATION" inputOutputType="OUTPUT" FromParty="BUYER">
<Instruction instructionLevel="DESIGN" instructionId="1234">DO IT</Instruction>
</Rate>';
$xml = simplexml_load_string($XML_BLOB);
$content = (string)$xml->Instruction;
php > var_dump($content);
string(5) "DO IT"
现在,您可以使用预期的层次结构访问它:
php > echo $xml->Rate->Instruction;
DO IT
或者,您可以使用Xpath表达式:
$instruction = $xml->xpath("Rate/Instruction");
$content = (string)$instruction[0];
php > var_dump($content);
string(5) "DO IT"
$XML\u BLOB=
做吧
';
$xml=simplexml\u load\u字符串($xml\u BLOB);
foreach($xml->xpath(//Instruction/text())作为$url){
echo$url;
};
$result=$xml->xpath(“速率/指令”)代码>这行吗?
$XML_DOC = '
<root>
<Rate maxRate="HIGH" Type="PROD" situs="DESTINATION" inputOutputType="OUTPUT" FromParty="BUYER">
<Instruction instructionLevel="DESIGN" instructionId="1234">DO IT</Instruction>
</Rate>
</root>';
php > echo $xml->Rate->Instruction;
DO IT
$instruction = $xml->xpath("Rate/Instruction");
$content = (string)$instruction[0];
php > var_dump($content);
string(5) "DO IT"
$XML_BLOB = '
<Rate maxRate="HIGH" Type="PROD" situs="DESTINATION" inputOutputType="OUTPUT" FromParty="BUYER">
<Instruction instructionLevel="DESIGN" instructionId="1234">DO IT</Instruction>
</Rate>';
$xml = simplexml_load_string($XML_BLOB);
foreach( $xml->xpath("//Instruction/text()") as $url ) {
echo $url;
};