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 8027725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:53:45+00:00 2026-06-04T23:53:45+00:00

I am trying to read/update/delete the XML file on the basis of value found.

  • 0

I am trying to read/update/delete the XML file on the basis of value found.

I have a XML with name 123456.xml with below format.

<ps>
  <p n="359" u="/ae/arabic/plan_book/plan_and_book.aspx"/>
  <p n="277" u="/ae/english/plan_book/plan_and_book.aspx"/>
  <p n="410" u="/ao/english/plan_book/plan_and_book.aspx"/>
</ps>

Now my new method in java will get Filepath (c://java/Files/12345.xml), n(277 – the value which will be checked in file) and U (“/de/english/plan_book/plan_and_book.aspx”).

Logic for my java method will as below, but really don’t know how to write.

Adding/Appending Method Logic:

  1. Open the file c://java/Files/12345.xml
  2. Search for all nodes and find the basis of value of n(277). There will be only one record for 277
  3. If this value exists in the file then no updates are required else add the new node in xml file, so for example if the value of n would have been (777), as this attribute record does not exists in file then it would have added a new record in file (<p n="777" u="/ao/english/plan_book/plan_and_book.aspx"/>).
  4. Save the updated XML on same location.

Deleting Method Logic:

  1. Open the file c://java/Files/12345.xml
  2. Search for all nodes and find on the basis of value of n(277). There will be only one record for 277.
  3. If this value exists in node attribute “n” then it will delete that node from the xml, else no update required.
  4. Save the updated XML on same location.

Would appreciate if you share some good example or links for above implementaion.

Thanks.

  • 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-06-04T23:53:47+00:00Added an answer on June 4, 2026 at 11:53 pm

    This kind of processing is usually easier and simpler (no regEx required) to specify in XSLT than in an imperative language.

    The XSLT transformation below can be used directly, or it can give an idea how to implement the same algorithm in another language:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pAction" select="'delete'"/>
     <xsl:param name="pN" select="277"/>
     <xsl:param name="pU" select="'/de/english/plan_book/plan_and_book.aspx'"/>
    
     <xsl:template match="node()|@*" name="identity">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="ps">
      <ps>
        <xsl:apply-templates select=
         "*[not($pAction = 'delete')]
         |
          *[$pAction = 'delete' and not(@n = $pN)]
         "/>
        <xsl:if test="$pAction = 'add' and not(p[@n = $pN])">
          <p n="{$pN}" u="{$pU}"/>
        </xsl:if>
      </ps>
     </xsl:template>
    
     <xsl:template match="p">
      <xsl:choose>
        <xsl:when test="not(@n = $pN)">
          <xsl:call-template name="identity"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="not($pAction = 'delete')">
              <xsl:call-template name="identity"/>
          </xsl:if>
         </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <ps>
        <p n="359" u="/ae/arabic/plan_book/plan_and_book.aspx"/>
        <p n="277" u="/ae/english/plan_book/plan_and_book.aspx"/>
        <p n="410" u="/ao/english/plan_book/plan_and_book.aspx"/>
    </ps>
    

    the wanted, correct result is produced:

    <ps>
       <p n="359" u="/ae/arabic/plan_book/plan_and_book.aspx"/>
       <p n="410" u="/ao/english/plan_book/plan_and_book.aspx"/>
    </ps>
    

    when the parameter $pAction is changed to:

     <xsl:param name="pAction" select="''add'"/>
    

    then the result of the transformation is the same XML document (unchanged).

    When the parameter is:

     <xsl:param name="pAction" select="''add'"/>
    

    and the XML document is:

    <ps>
        <p n="359" u="/ae/arabic/plan_book/plan_and_book.aspx"/>
        <p n="410" u="/ao/english/plan_book/plan_and_book.aspx"/>
    </ps>
    

    then the result is:

    <ps>
       <p n="359" u="/ae/arabic/plan_book/plan_and_book.aspx"/>
       <p n="410" u="/ao/english/plan_book/plan_and_book.aspx"/>
       <p n="277" u="/de/english/plan_book/plan_and_book.aspx"/>
    </ps>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read in an XML file that I have saved to
I'm trying to read an ontology manually designed on Protege 4 to update It
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
Iam trying to read a binary file to memory and pass the starting address
I am trying to read some XML code from a website, and am having
I have been trying to read up on GCD and trying to figure it
I am trying to read cells value from asp.net GridView control in Client Site
Trying to read an RSS and select information using Linq but can't seem to
After trying to read various articles on sending emails with attachments in PHP (I
Im trying to read a column of String values from my DB. Im trying

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.