您好我知道这里有很多关于这三个主题组合起来更新XML条目的问题,但似乎每个人都对特定问题非常具体.
我花了一些时间试图理解XPath及其方式,但我仍然无法得到我需要做的事情.
开始了
我有这个XML文件
<?xml version="1.0" encoding="UTF-8"?>
<storagehouse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
<item id="c7278e33ef0f4aff88da10dfeeaaae7a">
<name>HDMI Cable 3m</name>
<weight>0.5</weight>
<category>Cables</category>
<location>B3</location>
</item>
<item id="df799fb47bc1e13f3e1c8b04ebd16a96">
<name>Dell U2410</name>
<weight>2.5</weight>
<category>Monitors</category>
<location>C2</location>
</item>
</storagehouse>
Run Code Online (Sandbox Code Playgroud)
我想要做的是在需要时更新/编辑上面的任何节点.我会为此做一个Html表格.但我最大的抱怨是如何找到并更新所需节点并进行更新?
在这里,我有一些我想做的事情
<?php
function fnDOMEditElementCond()
{
$dom = new DOMDocument();
$dom->load('storage.xml');
$library = $dom->documentElement;
$xpath = new DOMXPath($dom);
// I kind of understand this one here
$result = $xpath->query('/storagehouse/item[1]/name');
//This one not so much
$result->item(0)->nodeValue .= ' Series';
// This will remove the CDATA property of the element.
//To retain it, delete …Run Code Online (Sandbox Code Playgroud)