2011-07-24 11 views
39

org.w3c.domのNode.getTextContent()に問題があります。Java 1.6.0_20のEclipse Node.getTextContent()

String name = document.getElementsByTagName("name").item(0).getTextContent(); 

、私にThe method getTextContent() is undefined for the type Nodeを与える日食:私は、コードブロックを以下しています。私が理解していない問題は何ですか?

ありがとうございます。


編集:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>FBApp</groupId> 
    <artifactId>FBApp</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <repositories> 
     <repository> 
      <id>java.net.maven1</id> 
      <name>java.net</name> 
      <url>http://download.java.net/maven/1</url> 
     </repository> 
     <repository> 
      <id>maven2-repository.java.net</id> 
      <name>Java.net Repository for Maven</name> 
      <url>http://download.java.net/maven/2/</url> 
     </repository> 
    </repositories> 

    <dependencies> 
     <dependency> 
      <groupId>javax.faces</groupId> 
      <artifactId>jsf-api</artifactId> 
      <version>1.2</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax.faces</groupId> 
      <artifactId>jsf-impl</artifactId> 
      <version>1.2</version> 
      <type>jar</type> 
      <classifier>NIGHTLY_20060227</classifier> 
      <scope>compile</scope> 
     </dependency>  
     <dependency> 
      <groupId>commons-beanutils</groupId> 
      <artifactId>commons-beanutils</artifactId> 
      <version>1.7.0</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-beanutils</groupId> 
      <artifactId>commons-beanutils-bean-collections</artifactId> 
      <version>1.7.0</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-beanutils</groupId> 
      <artifactId>commons-beanutils-core</artifactId> 
      <version>1.7.0</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-codec</groupId> 
      <artifactId>commons-codec</artifactId> 
      <version>1.3</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-collections</groupId> 
      <artifactId>commons-collections</artifactId> 
      <version>3.1</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-digester</groupId> 
      <artifactId>commons-digester</artifactId> 
      <version>1.7</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-el</groupId> 
      <artifactId>commons-el</artifactId> 
      <version>1.0</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-fileupload</groupId> 
      <artifactId>commons-fileupload</artifactId> 
      <version>1.0</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-lang</groupId> 
      <artifactId>commons-lang</artifactId> 
      <version>2.2</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.1.1</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-validator</groupId> 
      <artifactId>commons-validator</artifactId> 
      <version>1.1.4</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>oro</groupId> 
      <artifactId>oro</artifactId> 
      <version>2.0.8</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 

     <dependency> 
      <groupId>com.google.code.facebookapi</groupId> 
      <artifactId>facebook-java-api</artifactId> 
      <version>3.0.2</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.code.facebookapi</groupId> 
      <artifactId>facebook-java-api-annotation-processor</artifactId> 
      <version>3.0.2</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.code.facebookapi</groupId> 
      <artifactId>facebook-java-api-schema</artifactId> 
      <version>3.0.2</version> 
      <type>jar</type> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.4.2</version> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>jcl104-over-slf4j</artifactId> 
      <version>1.4.2</version> 
      <scope>runtime</scope> 
     </dependency>   
    </dependencies> 
</project> 

これはのpom.xmlとorg.w3c.domのが含まれていコモンズ・消化ニーズのXML-APIを-1.0b2です。私はこれが依存問題だと思う。

答えて

138

eclipseでプロジェクトのプロパティに移動する必要があります。次に、 "Java Build Path"を選択し、 "Order and Export"を選択します。ここでは、依存関係の順序を並べ替えることができます。 JREがMaven Dependenciesより上位にあることを確認します。

+1

これは、EclipseとMavenが多くのことを解決するソリューションです。どうもありがとう。 – fiskeben

+1

getNodeValue()の方が良いかもしれませんが、これは私にとってはすばやい修正として機能しました。 – JBCP

+0

ええ、それは私のために罰金を働いた! +1 – arthur

18

は、使用してみてください:

document.getElementsByTagName("name").item(0).getFirstChild().getNodeValue(); 

それはいくつかのケースでgetTextContent()よりも "安全な" 方法です私の知る限り。

+0

これは実際には同じ効果がありません。 COMMENT_NODEノードとPROCESSING_INSTRUCTION_NODEノードを除く、すべての子ノードのtextContent属性値を連結したものです。ノードに子がない場合は空の文字列です。 – teknopaul

8

私は古い記事ですけど、これに達した人のために、私は同様の問題があったとして示されている手順を使用して、それを修正:

http://mergetag.com/the-method-gettextcontent-is-undefined-for-the-type-node/

すなわち

org.w3c.dom.Node.getTextContent() is only available as of Java 1.5もの宣言を注意をNodexml-apis-1.0.b2.jarは問題のあるものです。 Properties> Java Build Path> Order and Exportタブに移動し、xml-apis-1.0.b2.jarを先頭に移動します。

+0

これはこの質問に対する正解です。 – Sudar

+0

リンク/投稿が死んでしまう可能性があるため、解決策を書くことを検討してください。 –

+0

パコ:このような素晴らしいソリューションに感謝します。それをキャッチアップ:) –