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

  • SEARCH
  • Home
  • 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 7663071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:57:51+00:00 2026-05-31T13:57:51+00:00

I am newbie in XML parsing world. I found solution for reading xml file

  • 0

I am newbie in XML parsing world. I found solution for reading xml file with ‘namespaces’ as given below. I refered this stackoverflow link Default XML namespace, JDOM, and XPath and reading Element works. But I am not able to modify the element. Here goes my problem statements.

My xml file looks like this.

<?xml version="1.0" encoding="UTF-8"?>
<ProofSpecification xmlns="http://www.zurich.ibm.com/security/idemix"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.zurich.ibm.com/security/idemix ProofSpecification.xsd">

    <Declaration>
        <AttributeId name="id1" proofMode="unrevealed" type="string" />
        <AttributeId name="id2" proofMode="unrevealed" type="string" />
    </Declaration>

    <Specification>
        <Credentials>
            <Credential issuerPublicKey="file:/Users/ipk.xml"
            credStruct="file:/Users/CredStruct_ResUAC.xml" name="SpecResUAC">
                <Attribute name="FirstName">id1</Attribute>
                <Attribute name="LastName">id2</Attribute>
            </Credential>
        </Credentials>

        <Pseudonyms>
            <Pseudonym name="pseudonym"></Pseudonym>
            <DomainPseudonym>1331859289489</DomainPseudonym>
        </Pseudonyms>

            <Messages />
    </Specification>
</ProofSpecification>

And my java code snippet looks like this.

public class ModifyXMLFileJDom {

    public static void main(String[] args) throws JDOMException, IOException {

      try {
        SAXBuilder builder = new SAXBuilder();
        File xmlFile = new File("/blabla/ProofSpecResUAC_old.xml");

        Document doc = (Document) builder.build(xmlFile); 

        XPath xpath = XPath.newInstance("x:ProofSpecification/x:Specification/x:Pseudonyms/x:DomainPseudonym");
        xpath.addNamespace("x", doc.getRootElement().getNamespaceURI());
        System.out.println("domainPseudonym: "+xpath.valueOf(doc));
        xpath.setVariable("555555", doc);

        XMLOutputter xmlOutput = new XMLOutputter();

        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter("/blabla/proofSpecOut.xml"));

        System.out.println("File updated!");
      } catch (IOException io) {
        io.printStackTrace();
      } catch (JDOMException e) {
        e.printStackTrace();
      }
    }
}

This piece of code works fine and Reading Element “domainPseudonym” works.

But I want to modify this element from 
 <DomainPseudonym>1331859289489</DomainPseudonym> to
 <DomainPseudonym>555555</DomainPseudonym>

I tried modifying using function xpath.setVariable(“555555”, doc) but not working and not giving out any error. The end result is that it copies the same content to the new xml file “proofSpecOut.xml”.

  • 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-31T13:57:52+00:00Added an answer on May 31, 2026 at 1:57 pm

    XPath is not used for modifying the xml, only for finding parts of it. XPath.setVariable() is only for setting variables in your xpath expression. You want to use XPath.selectSingleNode() to retrieve one of the Elements of your document and then you want to modify that directly using Element.setText().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

XML/XSL newbie here, so please forgive my ignorance. This is the xml input given
An XSLT-newbie problem: I need to substitute a text value in XML-file. All other
this is a really newbie question: How can I output XML with Spring MVC,
I am a newbie and was trying to traverse a ajax loaded xml file.
F# newbie I have 2 XML files in 2 folders c:\root\a\file.xml and c:\root\b\file.xml They
Hi i'm parsing an XML file using PHP to create another XML file in
I'm a LINQ to XML newbie, and a KML newbie as well; so bear
I'll admit, I'm an XML newbie. I'm having trouble validating some xml against a
I'm a newbie when it comes to properties, and I read that XML is
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie

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.