1
getElementsByTagName関数は、子をXMLブロブとして返すことができますか?PHP DOMDocument getElementsByTagName生のXMLを返します
getElementsByTagName関数は、子をXMLブロブとして返すことができますか?PHP DOMDocument getElementsByTagName生のXMLを返します
DOMDocument::getElementsByTagName()
返信a DOMNodeList
インスタンス。 DOMDocument::saveXML()
を使用して、生のXMLを文字列に連結したままにして、DOMNode
sを反復することができます。
<?php
$a = '<root>
<prueba>
<testtag value="1"/>
</prueba>
<notprueba>
<testtag value="1"/>
</notprueba>
<prueba>
<testtag value="2"/>
</prueba>
</root>';
$doc = new DOMDocument;
$doc->loadXML($a);
$x = new DOMXPath($doc);
$nodes = $doc->getElementsByTagName("prueba");
$xml = "";
foreach ($nodes as $node) {
$xml .= $doc->saveXML($node);
}
var_dump(htmlentities($xml));
これは、ノードのリストを返します - あなたは「XMLブロブ」を言うときあなたは何をしたいかわかりません –