PHP - 从xml获取值

我对从xml获取值有一些问题。</ p>

XML look 喜欢</ p>

 &lt;?xml version =“1.0”encoding =“UTF-8”?&gt; 
&lt;?xml-stylesheet type =“text / xsl”href = “http://crd.gov.pl/xml/schematy/UPO/2008/05/09/UPO.xsl"?>
<pos:Document xmlns:pos =”SOMEURL“
xmlns:xsi =”http ://www.w3.org/2001/XMLSchema-instance“&gt;
&lt; pos:DescribeDoc /&gt;
&lt; pos:UPD&gt;
&lt; pos:IdDoc&gt; procotol-UPD2198338&lt; / pos: IdDoc&gt;
&lt; pos:IdCases&gt; 221872&lt; / pos:IdCases&gt;
&lt; pos:additionalInfo TypeInfo =“Source”&gt;某些字符串&lt; / pos:additionalInfo&gt;
&lt; / pos:UPD&gt;
...
</ code> </ pre>

我一般尝试进入pos:IdCases。
我尝试这段代码:</ p>

   $ domContent = new SimpleXMLElement(((string)$ content),LIBXML_COMPACT); 
$ test = $ domContent-&gt; xpath('/ pos:Document / pos:UPD / *');
foreach($ test as $ node){
print_r($ node)
}
</ code> </ pre>

我得到了一些对象,例如</ p>

   SimpleXMLElement Object 

[0] =&gt; procotol-UPD2198338

SimpleXMLElement对象

[0] =&gt; 221872

SimpleXMLElement对象

[@attributes] =&gt;数组

[ TypeInfo] =&gt; Source

[0] =&gt;某些字符串

</ code> </ pre>

但我必须得到pos:IdCases。 我不能使用索引[1],因为顺序可以改变。</ p>

我的问题是:
我如何在节点中获取值:pos:IdCases
我无法添加id或 另一个信息到节点,因为这个xml已签名(XADES)。</ p>

你能给我一些建议吗? 感谢您的帮助</ p>
</ div>

展开原文

原文

I have a some problem with get value from xml.

XML look like

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://crd.gov.pl/xml/schematy/UPO/2008/05/09/UPO.xsl"?>
<pos:Document xmlns:pos="SOMEURL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <pos:DescribeDoc/>
   <pos:UPD>
      <pos:IdDoc>procotol-UPD2198338</pos:IdDoc>
      <pos:IdCases>221872</pos:IdCases>
      <pos:additionalInfo TypeInfo="Source">Some string</pos:additionalInfo>
   </pos:UPD>
...

I general try to get to pos:IdCases. I try this code:

$domContent = new SimpleXMLElement(((string) $content), LIBXML_COMPACT);
$test = $domContent->xpath('/pos:Document/pos:UPD/*');
foreach($test as $node){
    print_r($node)
}

I get a some object such as

SimpleXMLElement Object
(
     [0] => procotol-UPD2198338
)

SimpleXMLElement Object
(
    [0] => 221872
)

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [TypeInfo] => Source
        )

    [0] => Some string
)

But I must get to pos:IdCases. I can't use index [1] because order can change.

My question is: How can I get to value in node: pos:IdCases I can't add id or another info to node because this xml was signed (XADES).

Can you give me some advice? Thanks for help

1个回答



只需更改XPath以匹配&lt; Pos:IdCases /&gt; </ code>节点:</ p>

  $ test = $ domContent-&gt; xpath('/ pos:Document / pos:UPD / pos:IdCases'); 
</ code> </ pre>
</ DIV>

展开原文

原文

Simply change the XPath to match the <Pos:IdCases/> node:

$test = $domContent->xpath('/pos:Document/pos:UPD/pos:IdCases');

dongmi0760
dongmi0760 ....这显然是明显的......谢谢
6 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐