在php中帮助DOMDocument类 [英] help with DOMDocument class in php
问题描述
这里是我的xml DOM。
here is my xml DOM.
<entities>
<entity id="7006276">
<title>xxx</title>
<entities>
<entity id="7877579">
<title>xxx</title>
<entities>
我想获得ID为7006276的实体,所以我可以访问其实体为此创建一些实体元素。
i want to get the 'entity' with id 7006276 so i could access its child 'entities' to create some 'entity' elements for it.
我尝试过:
$this->xmlDocument = new DOMDocument();
// some code creating the above elements (you dont have to care about this comment code...it just creates the above xml structure
// $this->xmlDocument->createElement('entity');
// $sourceEntityElement->appendChild($newEntityElement);
// and so on...
// now i want to get the entities mentioned...
$xmlEntities = $this->xmlDocument->getElementById('7006276')->entities;
但它似乎不起作用任何想法我如何得到它,所以我可以创建更多的实体元素
but it doesnt seem to work. any idea how i get it so i can create more 'entity' elements?
推荐答案
现在,当您调用 DOMDocument :: getElementById
时,PHP不知道要查找什么属性,根据 getElementById
的文档,您需要要设置通知PHP关于您的 id
属性与 DOMElement :: setIdAttrib ute
或使用 DOMDocument :: validate
的DTD验证您的文档。
Right now, PHP doesn't know what attribute to look for when you call DOMDocument::getElementById
. According to the documentation for getElementById
, you need to either set inform PHP about your id
attribute with DOMElement::setIdAttribute
or validate your document against a DTD with DOMDocument::validate
.
这篇关于在php中帮助DOMDocument类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!