Php 尝试使用xpath搜索adobe flash xml文件

Php 尝试使用xpath搜索adobe flash xml文件,php,xml,xpath,Php,Xml,Xpath,我正在创建一个网页来更新Adobe flash项目XML文件。它是用php编写的,使用简单的XML和XPath。唯一的问题是xPath不会搜索和保存文件。我尝试使用一个基本的XML文件,xPath可以工作 我试图找到一个特定的节点“,并替换它的相关内容 下面是一个示例XML文件: <DOMSymbolItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ns.adobe.com/xfl/2008/"

我正在创建一个网页来更新Adobe flash项目XML文件。它是用php编写的,使用简单的XML和XPath。唯一的问题是xPath不会搜索和保存文件。我尝试使用一个基本的XML文件,xPath可以工作

我试图找到一个特定的节点
,并替换它的相关内容

下面是一个示例XML文件:

<DOMSymbolItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ns.adobe.com/xfl/2008/" name="Bt_Section manager" itemID="4725e7f8-000000db" symbolType="button" lastModified="1193667148">
  <timeline>
    <DOMTimeline name="Bt_Section manager">
      <layers>
        <DOMLayer name="Layer 1" color="#4F80FF" current="true" isSelected="true">
          <frames>
            <DOMFrame index="0" keyMode="9728">
              <elements>
                <DOMShape>
                  <fills>
                    <FillStyle index="1">
                      <SolidColor color="#FFDB62"/>
                    </FillStyle>
                  </fills>
                  <strokes>
                    <StrokeStyle index="1">
                      <SolidStroke scaleMode="normal" weight="2">
                        <fill>
                          <SolidColor/>
                        </fill>
                      </SolidStroke>
                    </StrokeStyle>
                  </strokes>
                  <edges>
                    <Edge fillStyle1="1" strokeStyle="1" edges="!809.5 0|5854 1.5!5854 1.5|6702 1188!6702 1188|0 1188!0 1188|809.5 0"/>
                  </edges>
                </DOMShape>
                <DOMStaticText selected="true" fontRenderingMode="standard" left="-112.25" width="141.55" height="46.7" isSelectable="false">
                  <matrix>
                    <Matrix a="0.754364013671875" d="0.746505737304688" tx="193.75" ty="14.1"/>
                  </matrix>
                  <textRuns>
                    <DOMTextRun>
                      <characters>Section manager</characters>
                      <textAttrs>
                        <DOMTextAttrs alignment="center" aliasText="false" autoKern="false" useScreenSpacing="true" size="20" face="Arial-BoldMT"/>
                      </textAttrs>
                    </DOMTextRun>
                  </textRuns>
                </DOMStaticText>
              </elements>
            </DOMFrame>
            <DOMFrame index="1" keyMode="9728">
              <elements>
                <DOMShape>
                  <fills>
                    <FillStyle index="1">
                      <SolidColor color="#FFDB62"/>
                    </FillStyle>
                  </fills>
                  <strokes>
                    <StrokeStyle index="1">
                      <SolidStroke scaleMode="normal" weight="2">
                        <fill>
                          <SolidColor/>
                        </fill>
                      </SolidStroke>
                    </StrokeStyle>
                  </strokes>
                  <edges>
                    <Edge fillStyle1="1" strokeStyle="1" edges="!809.5 0|5854 1.5!5854 1.5|6702 1188!6702 1188|0 1188!0 1188|809.5 0"/>
                  </edges>
                </DOMShape>
                <DOMStaticText selected="true" fontRenderingMode="standard" left="-112.25" width="141.55" height="46.7" isSelectable="false">
                  <matrix>
                    <Matrix a="0.754364013671875" d="0.746505737304688" tx="193.75" ty="14.1"/>
                  </matrix>
                  <textRuns>
                    <DOMTextRun>
                      <characters>Section manager</characters>
                      <textAttrs>
                        <DOMTextAttrs alignment="center" aliasText="false" autoKern="false" useScreenSpacing="true" size="20" face="Arial-BoldMT" fillColor="#FF6600"/>
                      </textAttrs>
                    </DOMTextRun>
                  </textRuns>
                </DOMStaticText>
             </elements>
            </DOMFrame>
          </frames>
        </DOMLayer>
      </layers>
    </DOMTimeline>
  </timeline>
</DOMSymbolItem>

部门经理
部门经理
我试过带DOM和不带DOM

这是我尝试过的,但没有结果

$xmlDoc=simplexml_load_file($XMLFile); 
$dom = new DOMDOcument();
$dom->loadXML($xmlDoc);
$xpath = new DOMXpath($dom);

echo "<pre>";

$result =   $xpath->query("//characters");              
      print_r($result);

echo "</pre>";
$xmlDoc=simplexml\u load\u文件($XMLFile);
$dom=新的DOMDOcument();
$dom->loadXML($xmlDoc);
$xpath=newdomxpath($dom);
回声“;
$result=$xpath->query(//字符);
打印(结果);
回声“;
谢谢你的帮助


Scott。

正如您在XML文档中看到的,
字符
节点没有名称空间前缀。这意味着它们使用默认名称空间,该名称空间由
xmlns
属性在根元素中定义。在给定的XML文档中,此默认命名空间为“”

在使用XPath查询其中的任何元素之前,只需注册此默认名称空间,如下所示:

注意,我在注册这个默认名称空间时使用了上面的“default”一词,稍后在使用XPath进行查询时再次使用了这个词。这个词可以是任何东西,不一定是“默认”

$xmlDoc=simplexml_load_file($XMLFile);

$xmlDoc->registerXPathNamespace("default", "http://ns.adobe.com/xfl/2008/");
$charactersNodes = $xmlDoc->xpath("//default:characters");