我尝试了多种代码组合,即使我认为我掌握了它,它也失败了!我总是回到“获取非对象错误的属性”我目前的一个是:
Notice: Trying to get property of non-object in {PROJECT_DIR} on line 11
无论如何,我正在尝试更改 .docx 文件 document.xml 文件中书签的节点值,并且我有一组书签 id => 书签名称,我正在使用简单的 foreach 遍历它们来编辑所有使用 SimpleXML 找到了书签,但是,我遇到了一些问题。
我目前的代码是:
if (file_exists('document.xml'))
{
$document = simplexml_load_file('document.xml');
}
echo $document->getName() . "<br />";
echo $document->document->body->{'w:bookmarkStart'};
我尝试从 echo 语句中删除 ->document 并将 {'w:bookmarkStart'} 更改为 bookmarkStart 但一切都证明无效,但是我说我尝试的上述更改没有返回通知,只是空白。我确定我还没有掌握这个 XML 东西的要点,而且我对它很菜鸟,这对你们来说可能很容易指出问题,但是代码示例的研究和使用已经事实证明对我无效;(我尝试编辑的 XML 文件的紧凑版本是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
<w:body>
<w:bookmarkStart w:id="0" w:name="MOREG"/>
<w:bookmarkEnd w:id="0"/>
</w:body>
</w:document>