Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用simplexml\u load\u字符串读取XML标记的值_Php_Xml - Fatal编程技术网

Php 如何使用simplexml\u load\u字符串读取XML标记的值

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

如何读取指令标记“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;
};