[英]SimpleXML: Getting attributes into variables
I am building my website with a central XML-file and SimpleXML. 我正在使用中央XML文件和SimpleXML构建我的网站。 The pages have some different features like the language.
这些页面具有一些不同的功能,例如语言。 I would like to put these features into the XML-file with attributes of the parent node:
我想将这些功能放入具有父节点属性的XML文件中:
<content>
<item id="one" lang="en">
<title>Hello</title>
</item>
</content>
I call a certain item by the id-attribute and I know how to call subnodes like : 我通过id属性调用某个项目,并且我知道如何调用子节点,例如:
$xml = simplexml_load_file('file.xml');
$lang = $bl->xpath('/content/item[@id="one"]/title/text()');
$lang = $lang[0]; echo $lang;
But how do I get the attribute LANG of an item with the id="one" into a variable? 但是,如何将具有id =“ one”的项的属性LANG转换为变量?
属性/content/item[@id="one"]/@lang
的路径属性data(/content/item[@id="one"]/@lang)
的值data(/content/item[@id="one"]/@lang)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.