在现有标签下使用php,xml

时间:2019-08-28 13:40:50

标签: php xml domdocument

我想在xml输出中的现有标签下创建一个新标签。 我使用的代码:

header('Content-Type: application/xml');
$xml = new DOMDocument();
$xml->preserveWhiteSpace = false;
$xml->validateOnParse = true;
$xml->formatOutput = true;
$xml->load(http://www.xxxx.com/xmlfile.xml');
$xml_string = $xml->saveXML();
echo $xml_string;

输出:

<Root>
  <Products>
    <Product>   
      <Images>  
            * I want to create a label here to <image> </image> *
      </Images>
    </Product>
  </Products>
</Root>

我想在标签之间放置一个“图像” 标签

$image->appendChild($xml->createElement('Image'));

但是我没有得到想要的结果:) 我将使用“图像”标签对图像进行分组,但是我需要创建一个优先级标签。

<images>
    <image> http://example.com/image.jpg </image>
    <image> http://example.com/image.jpg </image>
    <image> http://example.com/image.jpg </image>
</images>

0 个答案:

没有答案