Php 从XML响应打印值

Php 从XML响应打印值,php,Php,我正在使用web服务。我发送请求并获取xml作为响应。 这就是我要发送的内容: $s = new soapclient($conDetails['url'],array('wsdl')); $params = new stdClass; $paramsStr = ' <GetPackItinerary UserID="'.$conDetails['UsrId'].'" SessionID="'.$conDetails['Session'].'" >

我正在使用web服务。我发送请求并获取xml作为响应。 这就是我要发送的内容:

$s = new soapclient($conDetails['url'],array('wsdl'));
$params = new stdClass;
$paramsStr = '
            <GetPackItinerary UserID="'.$conDetails['UsrId'].'" SessionID="'.$conDetails['Session'].'" >
                <root>
                    <ItinId>'.$_GET['int'].'</ItinId>
                </root>
            </GetPackItinerary>
            ';
$params->xmlRequest = $paramsStr;

$result = $s->__call("SubmitXmlString",array($params));
$s=newsoapclient($conDetails['url'],array('wsdl');
$params=新的stdClass;
$paramsStr='1〕
“.$\u获取['int']”
';
$params->xmlRequest=$paramsStr;
$result=$s->_调用(“SubmitXmlString”,数组($params));
如果我打印Resalt,其外观如下:

<GetPackItinerary Cnt="1">
    <int id="39">
        <header>
            <ItinId>39</ItinId>
            <Name>text for tour</Name>
            <Class>STD</Class>
            <Days>10</Days>
            <Text/>
            <Include>text for tour</Include>
            <NotInclude>text for tour</NotInclude>
            <Url>http://www.geotours.co.il</Url>
            <Status>OK</Status>
        </header>
        <day id="1">
            <ItinId>39</ItinId>
            <Destination/>
            <Day>1</Day>
            <Meal/>
            <Header>text for day 1</Header>
            <Text>some text</Text>
            <Include>some text</Include>
            <NotInclude/>
        </day>
        <day id="2">
            <ItinId>39</ItinId>
            <Destination/>
            <Day>2</Day>
            <Meal/>
            <Header>text for day 2</Header>
            <Text>some text 2</Text>
            <Include>some text 2</Include>
            <NotInclude/>
        </day>
    </int>
</GetPackItinerary>

39
旅游文本
性病科
10
旅游文本
旅游文本
http://www.geotours.co.il
好啊
39
1.
第1天的文本
一些文本
一些文本
39
2.
第2天的文本
一些文本2
一些文本2
我的问题是-我到底从WS得到了什么?是XML吗?奥贝特?
还有-我如何打印一些值,例如-在“header”标记中的标记“name”(旅游文本)?

我觉得它像是“XML”。您可以使用SimpleXML访问XML的元素。这里有一个方法:-

<?php
//generate a file from **$result** and store it in your directory.
//save it as myfile.xml, which would be handled by simplexml_load_file
$fileHandler = simplexml_load_file("myfile.xml");
echo $fileHandler->GetPackItinerary->int->header->Name;

//outputs :- text for tour
?>

在我看来,它似乎是“XML”。您可以使用SimpleXML访问XML的元素。这里有一个方法:-

<?php
//generate a file from **$result** and store it in your directory.
//save it as myfile.xml, which would be handled by simplexml_load_file
$fileHandler = simplexml_load_file("myfile.xml");
echo $fileHandler->GetPackItinerary->int->header->Name;

//outputs :- text for tour
?>

使用标准的
DOMDocument
了解一些基本知识后,就可以很容易地在各个节点之间导航,但是下面应该给您一个大致的想法

$strxml='<GetPackItinerary Cnt="1">
            <int id="39">
                <header>
                    <ItinId>39</ItinId>
                    <Name>text for tour</Name>
                    <Class>STD</Class>
                    <Days>10</Days>
                    <Text/>
                    <Include>text for tour</Include>
                    <NotInclude>text for tour</NotInclude>
                    <Url>http://www.geotours.co.il</Url>
                    <Status>OK</Status>
                </header>
                <day id="1">
                    <ItinId>39</ItinId>
                    <Destination/>
                    <Day>1</Day>
                    <Meal/>
                    <Header>text for day 1</Header>
                    <Text>some text</Text>
                    <Include>some text</Include>
                    <NotInclude/>
                </day>
                <day id="2">
                    <ItinId>39</ItinId>
                    <Destination/>
                    <Day>2</Day>
                    <Meal/>
                    <Header>text for day 2</Header>
                    <Text>some text 2</Text>
                    <Include>some text 2</Include>
                    <NotInclude/>
                </day>
            </int>
        </GetPackItinerary>';

$dom=new DOMDocument;
$dom->loadXML( $strxml );

$root=$dom->getElementsByTagName('GetPackItinerary')->item(0);
$header=$dom->getElementsByTagName('header')->item(0);
$days=$dom->getElementsByTagName('day');

$tour=$header->childNodes->item(3);

echo $tour->tagName.': '.$tour->nodeValue.BR;/* Name: text for tour */

foreach( $days as $node ){/* 1,3,5,7,9 etc ~ even numbers are textNodes! */
    echo $node->childNodes->item(9)->tagName.': '.$node->childNodes->item(9)->nodeValue.BR;
}
$strxml='1!'
39
旅游文本
性病科
10
旅游文本
旅游文本
http://www.geotours.co.il
好啊
39
1.
第1天的文本
一些文本
一些文本
39
2.
第2天的文本
一些文本2
一些文本2
';
$dom=新的DOMDocument;
$dom->loadXML($strxml);
$root=$dom->getElementsByTagName('GetPackItinerary')->项(0);
$header=$dom->getElementsByTagName('header')->item(0);
$days=$dom->getElementsByTagName('day');
$tour=$header->childNodes->item(3);
echo$tour->tagName.:'.$tour->nodeValue.BR;/*名称:旅游文本*/
foreach($node的天数){/*1,3,5,7,9等~偶数是textNodes*/
echo$node->childNodes->item(9)->tagName.:'。$node->childNodes->item(9)->nodeValue.BR;
}

使用标准的
DOMDocument
了解一些基本知识后,就可以很容易地在各个节点之间导航,但是下面应该给您一个大致的想法

$strxml='<GetPackItinerary Cnt="1">
            <int id="39">
                <header>
                    <ItinId>39</ItinId>
                    <Name>text for tour</Name>
                    <Class>STD</Class>
                    <Days>10</Days>
                    <Text/>
                    <Include>text for tour</Include>
                    <NotInclude>text for tour</NotInclude>
                    <Url>http://www.geotours.co.il</Url>
                    <Status>OK</Status>
                </header>
                <day id="1">
                    <ItinId>39</ItinId>
                    <Destination/>
                    <Day>1</Day>
                    <Meal/>
                    <Header>text for day 1</Header>
                    <Text>some text</Text>
                    <Include>some text</Include>
                    <NotInclude/>
                </day>
                <day id="2">
                    <ItinId>39</ItinId>
                    <Destination/>
                    <Day>2</Day>
                    <Meal/>
                    <Header>text for day 2</Header>
                    <Text>some text 2</Text>
                    <Include>some text 2</Include>
                    <NotInclude/>
                </day>
            </int>
        </GetPackItinerary>';

$dom=new DOMDocument;
$dom->loadXML( $strxml );

$root=$dom->getElementsByTagName('GetPackItinerary')->item(0);
$header=$dom->getElementsByTagName('header')->item(0);
$days=$dom->getElementsByTagName('day');

$tour=$header->childNodes->item(3);

echo $tour->tagName.': '.$tour->nodeValue.BR;/* Name: text for tour */

foreach( $days as $node ){/* 1,3,5,7,9 etc ~ even numbers are textNodes! */
    echo $node->childNodes->item(9)->tagName.': '.$node->childNodes->item(9)->nodeValue.BR;
}
$strxml='1!'
39
旅游文本
性病科
10
旅游文本
旅游文本
http://www.geotours.co.il
好啊
39
1.
第1天的文本
一些文本
一些文本
39
2.
第2天的文本
一些文本2
一些文本2
';
$dom=新的DOMDocument;
$dom->loadXML($strxml);
$root=$dom->getElementsByTagName('GetPackItinerary')->项(0);
$header=$dom->getElementsByTagName('header')->item(0);
$days=$dom->getElementsByTagName('day');
$tour=$header->childNodes->item(3);
echo$tour->tagName.:'.$tour->nodeValue.BR;/*名称:旅游文本*/
foreach($node的天数){/*1,3,5,7,9等~偶数是textNodes*/
echo$node->childNodes->item(9)->tagName.:'。$node->childNodes->item(9)->nodeValue.BR;
}

它看起来像XML,您需要使用
DOMDocument
SimpleXML
来响应为您提供此代码的内容:
echo gettype($result)
?@RomanPerekhrest-单词“object”看起来像XML,您需要使用
DOMDocument
SimpleXML
来响应此代码的内容:
echo gettype($result)?@RomanPerekhrest-单词“object”我必须保存在文件中吗?@roi,是的,那;s首选。我必须将其保存在文件中吗?@roi,是的,那个;A:那好。