2012-02-21 6 views
2

XMLTasksを使用してXMLファイルの一部の値を置き換えようとしていますが、他のツールを使用すると、私のxpathが正しいと言われますが、何が間違っているのか分かりません。XMLTasksを使用したAntからのXMLPathは、XMLファイルに異なる名前空間の要素がある場合には一致しません。

ここ

私が探していたファイル:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<project xmlns="http://www.netbeans.org/ns/project/1"> 
    <type>org.netbeans.modules.apisupport.project</type> 
    <configuration> 
     <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> 
      <code-name-base>simple.server.extension.cardgame</code-name-base> 
      <suite-component/> 
      <module-dependencies> 
       <dependency> 
        <code-name-base>marauroa.lib</code-name-base> 
        <build-prerequisite/> 
        <compile-dependency/> 
        <run-dependency> 
         <release-version>3</release-version> 
         <specification-version>8</specification-version> 
        </run-dependency> 
       </dependency> 
       <dependency> 
        <code-name-base>simple.server.lib</code-name-base> 
        <build-prerequisite/> 
        <compile-dependency/> 
        <run-dependency> 
         <release-version>0-1</release-version> 
         <specification-version>0.2</specification-version> 
        </run-dependency> 
       </dependency> 
      </module-dependencies> 
      <public-packages> 
       <package>dreamer.card.game</package> 
       <package>dreamer.card.game.model.events</package> 
       <package>dreamer.card.game.price</package> 
       <package>dreamer.card.game.storage</package> 
       <package>simple.server.extension</package> 
       <package>simple.server.extension.card</package> 
      </public-packages> 
      <class-path-extension> 
       <runtime-relative-path>ext/extension/x.jar</runtime-relative-path> 
       <binary-origin>../../Simple Marauroa Java/Card Game Extension/dist/x.jar</binary-origin> 
      </class-path-extension> 
      <class-path-extension> 
       <runtime-relative-path>ext/extension/y.jar</runtime-relative-path> 
       <binary-origin>../../Simple Marauroa Java/Card Game interface/dist/y.jar</binary-origin> 
      </class-path-extension> 
     </data> 
    </configuration> 
</project> 

そして、これは私が使用しているパス式である:ここで

/project/configuration/data/class-path-extension[1]/runtime-relative-path/text() 

は私がしようとしているタスクの関連する部分ですが実行:

<target name="s" depends="-define-xmltasks"> 
     <propertyselector property="subprojects" match="original.project.dir(.*)" select="\1"/> 
     <for list="${subprojects}" param="subproject"> 
      <sequential> 
       <xmltask source="nbproject/project.xml" dest="nbproject/project.xml" failWithoutMatch="true"> 
        <replace path="/project/configuration/data/class-path-extension[@{subproject}]/runtime-relative-path/text()" 
          withText="ext/extension/${[email protected]{subproject}.dist.jar}"/> 
        <replace path="/project/configuration/data/class-path-extension[@{subproject}]/binary-origin/text()" 
          withText="${[email protected]{subproject}}/dist/${[email protected]{subproject}.dist.jar}"/> 
       </xmltask> 
      </sequential> 
     </for> 
    </target> 

{サブ}は番号に解決し、既に数のためにそれを変更しようとしたが、同じ効果を持ちます@ 。何か案が?

+0

他の貴重なxpathツールについてはhttp://sourceforge.net/projects/xpe/files/xpe/20030304/を参照してください。使用可能なスタンドアロンおよびEclipseプラグインとして。 eclipse用の別のxpathプラグインは、Xpath-Developerです。http://www.bastian-bergerhoff.com/eclipse/features/web/XPathDeveloper/toc.html – Rebse

答えて

2

And this is the path expression I'm using:

/project/configuration/data/class-path-extension[1]/runtime-relative-path/text() 

一つの方法は、述語として名を指定することです。この変換の場合

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:copy-of select= 
    "/*[name()='project'] 
    /*[name()='configuration'] 
     /*[name()='data'] 
     /*[name()='class-path-extension'][1] 
      /*[name()='runtime-relative-path'] 
      /text() 
    "/> 
</xsl:template> 
</xsl:stylesheet> 

:基づく検証 -

/*[name()='project'] 
    /*[name()='configuration'] 
     /*[name()='data'] 
     /*[name()='class-path-extension'][1] 
      /*[name()='runtime-relative-path'] 
      /text() 

XSLT:ここ

を所望ノード(複数可)を選択し、このスタイルで記述されたXPath式であります提供されたXMLドキュメントに適用されます

<project xmlns="http://www.netbeans.org/ns/project/1"> 
    <type>org.netbeans.modules.apisupport.project</type> 
    <configuration> 
     <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> 
      <code-name-base>simple.server.extension.cardgame</code-name-base> 
      <suite-component/> 
      <module-dependencies> 
       <dependency> 
        <code-name-base>marauroa.lib</code-name-base> 
        <build-prerequisite/> 
        <compile-dependency/> 
        <run-dependency> 
         <release-version>3</release-version> 
         <specification-version>8</specification-version> 
        </run-dependency> 
       </dependency> 
       <dependency> 
        <code-name-base>simple.server.lib</code-name-base> 
        <build-prerequisite/> 
        <compile-dependency/> 
        <run-dependency> 
         <release-version>0-1</release-version> 
         <specification-version>0.2</specification-version> 
        </run-dependency> 
       </dependency> 
      </module-dependencies> 
      <public-packages> 
       <package>dreamer.card.game</package> 
       <package>dreamer.card.game.model.events</package> 
       <package>dreamer.card.game.price</package> 
       <package>dreamer.card.game.storage</package> 
       <package>simple.server.extension</package> 
       <package>simple.server.extension.card</package> 
      </public-packages> 
      <class-path-extension> 
       <runtime-relative-path>ext/extension/x.jar</runtime-relative-path> 
       <binary-origin>../../Simple Marauroa Java/Card Game Extension/dist/x.jar</binary-origin> 
      </class-path-extension> 
      <class-path-extension> 
       <runtime-relative-path>ext/extension/y.jar</runtime-relative-path> 
       <binary-origin>../../Simple Marauroa Java/Card Game interface/dist/y.jar</binary-origin> 
      </class-path-extension> 
     </data> 
    </configuration> 
</project> 

XPath式が評価され、選択したノードを出力にコピーされます

ext/extension/x.jar 

:インクリメンタル建物とXPath式の検証のためには、the XPath visualizerのようなツールを使用することができます。このツールは、何千人もの人々がXPathを楽しく学ぶのに役立ちました。

+0

それはありました!ありがとう! – javydreamercsw

+0

@javydreamercsw:どうぞよろしくお願いします。 –

2

projectdataの要素が異なる名前空間で宣言されているという問題があります。あなたは次のようにノード述語でlocal-name()属性を使用することがあります。

/*[local-name() = 'project'] ...

ます。またnamespace-uri属性を使用して名前空間を指定できますように

/*[local-name() = 'project' and namespace-uri() = 'http://www.netbeans.org/ns/project/1'] ...

とを。空ではない(デフォルト)名前空間にある接頭辞なしの名前に対処するための

+0

パスを次のように変更しました。path = "/ * [local-name( )= 'project'とnamespace-url()= 'http:// www。netbeans.org/ns/project/1 ']/configuration/* [local-name()=' data 'およびnamespace-url()=' http://www.netbeans.org/ns/nb-module-project/3 ']/class-path-extension [@ {サブプロジェクト}]/runtime-relative-path/text() "エラーが発生する:javax.xml.transform.TransformerException:関数が見つかりませんでした:namespace-url – javydreamercsw

+0

申し訳ありません、それは 'namespace-uri()'です – Wojteq

+0

uriに変更されましたが、まだ取得:サブタスクは一致を見つけることができませんでした – javydreamercsw

関連する問題