如何从XML文件中获取参数?

时间:2013-12-06 08:35:46

标签: php xml

我想从我的XML参数文件中获取href;这是我的代码:

$linkx = $params->get('linkx'); 
echo '<a href="$linkx"><p class="bottomp"> Find More </a>';

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

使用SimpleXMLXPath

的示例
<?php
$doc = new SimpleXMLELement( data() );
$fields = $doc->xpath('//form[@id="form2"]/field');

foreach( $fields as $f) {
    printf('name=%s, type=%s, label=%s%s', $f['name'], $f['type'], $f['label'], PHP_EOL);
}


function data() {
return <<< eot
<data>
    <form id="form1"></form>
    <form id="form2">
        <field name="linkx" type="text" label="Find More Link" description="Link to more news" />
        <field name="linky" type="text" label="..." description="---" />
    </form>
    <form id="form3"></form>
</data>
eot;
}

打印

name=linkx, type=text, label=Find More Link
name=linky, type=text, label=...
相关问题