Java 1.6.0_20 中的 Eclipse Node.getTextContent()

发布于 2024-11-26 08:20:24 字数 7437 浏览 1 评论 0原文

我在 org.w3c.dom 的 Node.getTextContent() 方面遇到麻烦。我有以下代码块:

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

Eclipse 给我 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,commons-digester需要包含org.w3c.dom的xml-apis-1.0b2。我认为这是一个依赖问题。

I am facing trouble with Node.getTextContent() of org.w3c.dom. I have following code block:

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

And eclipse giving me The method getTextContent() is undefined for the type Node. What is the problem I don't understand.

Thanks and regards.


Edit:

<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>

This is the pom.xml and the commons-digester needs xml-apis-1.0b2 which contains org.w3c.dom. I think this is a dependency problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白况 2024-12-03 08:20:24

您需要在 Eclipse 中转到该项目的“属性”。然后选择“Java Build Path”并选项卡“Order and Export”。在这里您可以安排依赖项的顺序。确保您的 JRE 高于 Maven 依赖项。

You need to go to Properties for the project in eclipse. Then select "Java Build Path" and tab "Order and Export". Here you can arrange the order of dependencies. Ensure that your JRE is higher up then Maven Dependencies.

爱本泡沫多脆弱 2024-12-03 08:20:24

尝试使用:

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

AFAIK 在某些情况下,它比 getTextContent() 更“安全”。

Try using:

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

AFAIK It's "safer" way than getTextContent() in some cases.

牵强ㄟ 2024-12-03 08:20:24

我知道这是一篇较旧的帖子,但对于达到此目的的任何人,我都遇到了类似的问题,并使用以下所示的步骤修复了它:

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

即, org.w3c.dom.Node.getTextContent() 仅在 Java 1.5 中可用,但还要注意 Node 的声明。 xml-apis-1.0.b2.jar 是有问题的。进入项目属性> Java 构建路径 > “订购和导出”选项卡,然后将 xml-apis-1.0.b2.jar 移动到顶部。

I know that is an older post, but for anyone who reached this I had a similar problem and fixed it using the steps indicated in:

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

Namely, org.w3c.dom.Node.getTextContent() is only available as of Java 1.5 but also note the declarations of Node. The xml-apis-1.0.b2.jar is the problematic one. Go into the project Properties > Java Build Path > Order and Export tab, and move xml-apis-1.0.b2.jar to the top.

没企图 2024-12-03 08:20:24

我遇到了类似的问题,并通过从 Java SDK 1.11 降级到 1.8 来修复它

I had a similar problem, and fixed it by downgrading from Java SDK 1.11 to 1.8

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文