Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:54:01+00:00 2026-05-26T02:54:01+00:00

Is there a java equivalent of .NET’s System.Xml.XmlNode.InnerXml ? I need to replace some

  • 0

Is there a java equivalent of .NET’s System.Xml.XmlNode.InnerXml?

I need to replace some words in an XML document.

I cannot use Java’s org.w3c.dom.Node.setTextContent() because this removes the XML nodes.

Thanks!

Source:

<body>
<title>Home Owners Agreement</title>
<p>The <b>good</b> thing about a Home Owners Agreement is that...</p>
</body>

Desired output:

<body>
<title>Home Owners Agreement</title>
<p>The <b>good</b> thing about a HOA is that...</p>
</body>

I only want text in <p> tags to be replaced. I tried the following:

replaceText(string term, string replaceWith, org.w3c.dom.Node p){
       p.setTextContent(p.getTextContent().replace(term, replaceWith));

}

The problem with the above code is that all the child nodes of p get lost.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:54:02+00:00Added an answer on May 26, 2026 at 2:54 am

    Okay, I figured out the solution.

    The key to this is that you don’t want to replace the text of the actual node. There is a actually a child representation of just the text. I was able to accomplish what I needed with this code:

    private static void replace(Node root){
        if (root.getNodeType() == root.TEXT_NODE){
            root.setTextContent(root.getTextContent().replace("Home Owners Agreement", "HMO"));
        }
        for (int i = 0; i < root.getChildNodes().getLength(); i++){ 
            outputTextOfNode(root.getChildNodes().item(i));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a Java equivalent to .NET's App.Config? If not is there a standard
I am looking for a Java equivalent to .NET's Snippet Compiler. Is there any
Is there a .NET equivalent of Java Web Start? I want a one-click, from
Is there any equivalent of Reactive Extensions (.NET) for Java? About Rx (Reactive Extensions)
Is there a.NET utility class equivalent to java.util.Arrays.hashCode() for arrays of intrinsic types such
Is there any equivalent for SAX (Java) in .Net? I am aware of XmlReader,
Is there a Java equivalent for ASP.NET Membership?
Is there an equivalent of the java.net.URLConnection class in .NET. , for example the
Is there an equivalent of Java Message Driven Beans for .Net?
Is there an equivalent in Java to VB.NET's optional parameters? Also is it possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.