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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:39:24+00:00 2026-06-16T01:39:24+00:00

I have returned the following String strFees720 which equals : <?xml version=1.0 encoding=UTF-8?> <Response>

  • 0

I have returned the following String strFees720

which equals :

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Fees720>
        <errorNode>
            <errorCode>0</errorCode>
            <errorMsg/>
            <errorSev/>
        </errorNode>
        <forwardScroll>       0093101200001117                0</forwardScroll>
        <backwardScroll>                                        </backwardScroll>
        <Field name="ACCID"><Value>93101200001034</Value></Field>
        <Field name="FPERIOD"><Value>2C</Value></Field>
        <Field name="STDATE"><Value>13 DEC 2012</Value></Field>
        <Field name="ENDATE"><Value>13 DEC 2012</Value></Field>
        <Field name="ADVDATE"><Value>19 DEC 2012</Value></Field>
        <Field name="DBDATE"><Value> F40LA1C   </Value></Field>
        <Field name="SNAME"><Value>N SINGLETON JG</Value></Field>
        <Field name="ACDESC"><Value>OVERDRAFT AAA</Value></Field>
        <Field name="TOTFEES"><Value>0</Value></Field>
        <Field name="DISCOUNT"><Value>0</Value></Field>
        <Field name="NETFEES"><Value>0</Value></Field>
        <Field name="CLRD_BAL"><Value>93101200001034</Value></Field>
        <Field name="ALLOW_RTE"><Value>0</Value></Field>
        <Field name="DISC_RTE"><Value>0</Value></Field>
        <Field name="ALLOW_TOT"><Value>0</Value></Field>
        <Field name="PCODE"><Value>0000000</Value></Field>
        <Field name="DRILLNSC"><Value>0</Value></Field>
        <Field name="DIALOG"><Value>9</Value></Field>
        <Field name="NUMLINES"><Value>1</Value></Field>
        <Field name="TOTLINES"><Value>0</Value></Field>
        <Field name="BPCUST"><Value>P</Value></Field>
        <Field name="NFEE_EXPDTE"><Value></Value></Field>
        <FEEDATA>
            <Field name="FCODE"><Value></Value></Field>
            <Field name="FEEDETS"><Value></Value></Field>
            <Field name="CHRG_TYPE"><Value></Value></Field>
            <Field name="DCODE"><Value></Value></Field>
            <Field name="VOLUME"><Value>0</Value></Field>
            <Field name="RATE"><Value>0</Value></Field>
            <Field name="TOTAL"><Value>0</Value></Field>
            <Field name="DRILL"><Value></Value></Field>
        </FEEDATA>
        <GROSSNETFEES>
            <Field name="FQUARTER"><Value>06 DEC 12    12 DEC 12</Value></Field>
            <Field name="GRSFEE"><Value>611960</Value></Field>
            <Field name="NFEE"><Value>611960</Value></Field>
            <Field name="FEEDISC"><Value>0</Value></Field>
        </GROSSNETFEES>
        <GROSSNETFEES>
            <Field name="FQUARTER"><Value>01 DEC 12    05 DEC 12</Value></Field>
            <Field name="GRSFEE"><Value>64850</Value></Field>
            <Field name="NFEE"><Value>64850</Value></Field>
            <Field name="FEEDISC"><Value>0</Value></Field>
        </GROSSNETFEES>
        <GROSSNETFEES>
            <Field name="FQUARTER"><Value>08 NOV 12    30 NOV 12</Value></Field>
            <Field name="GRSFEE"><Value>15866</Value></Field>
            <Field name="NFEE"><Value>15866</Value></Field>
            <Field name="FEEDISC"><Value>0</Value></Field>
        </GROSSNETFEES>
        <GROSSNETFEES>
            <Field name="FQUARTER"><Value>01 NOV 12    07 NOV 12</Value></Field>
            <Field name="GRSFEE"><Value>636</Value></Field>
            <Field name="NFEE"><Value>616</Value></Field>
            <Field name="FEEDISC"><Value>20</Value></Field>
        </GROSSNETFEES>
        <Field name="TOTGRSFEE"><Value>693312</Value></Field>
        <Field name="TOTNETFEE"><Value>693292</Value></Field>
    </Fees720>
</Response>

I would like to transform this xml string response into a new xml string

as follows:

    <?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Fees720>
        <errorNode>
            <errorCode>0</errorCode>
            <errorMsg/>
            <errorSev/>
        </errorNode>
        <forwardScroll>       0093101200001117                0</forwardScroll>
        <backwardScroll>                                        </backwardScroll>
        <accid>93101200001034</accid>
        <fperiod>2C</fperiod>
        <stdate>13 DEC 2012</stdate>
        <endate>13 DEC 2012</endate>
        <advdate>19 DEC 2012</advdate>
        <dbdate> F40LA1C   </dbdate>
        <sname>N SINGLETON JG</sname>
        <acdesc>OVERDRAFT AAA</acdesc>
        <totfees>0</totfees>
        <discount>0</discount>
        <netfees>0</netfees>
        <clrdbal>93101200001034</clrdbal>
        <allowrte>0</allowrte>
        <discrte>0</discrte>
        <allowtot>0</allowtot>
        <pcode>0000000</pcode>
        <drillnsc>0</drillnsc>
        <dialog>9</dialog>
        <numlines>1</numlines>
        <totlines>0</totlines>
        <bpcust>P</bpcust>
        <nfeeexpdte></nfeeexpdte>
        <feedata>
            <fcode></fcode>
            <feedets></feedets>
            <chrgtype></chrgtype>
            <dcode></dcode>
            <volume>0</volume>
            <rate>0</rate>
            <total>0</total>
            <drill></drill>
        </feedata>
        <grossnetfees>
            <fquarter>06 DEC 12    12 DEC 12</fquarter>
            <grsfee>611960</grsfee>
            <nfee>611960</nfee>
            <feedisc>0</feedisc>
        </grossnetfees>
        <grossnetfees>
            <fquarter>01 DEC 12    05 DEC 12</fquarter>
            <grsfee>64850</grsfee>
            <nfee>64850</nfee>
            <feedisc>0</feedisc>
        </grossnetfees>
        <grossnetfees>
            <fquarter>08 NOV 12    30 NOV 12</fquarter>
            <grsfee>15866</grsfee>
            <nfee>15866</nfee>
            <feedisc>0</feedisc>
        </grossnetfees>
        <grossnetfees>
            <fquarter>01 NOV 12    07 NOV 12</fquarter>
            <grsfee>636</grsfee>
            <nfee>616</nfee>
            <feedisc>20</feedisc>
        </grossnetfees>
        <totgrsfee>693312</totgrsfee>
        <totnetfee>693292</totnetfee>
    </Fees720>
</Response>

I’m thinking I need to do something along the lines of:

strFees720Transform = XSLTransformer.transform("mynewxsl.xsl", strFees720);

and transform the original xml into the new xml. Any advice on best way to do this please. Thanks

updated with method

    private String getServiceValue(String strXMLResponse, String strNode, String strService) throws ServletException{

    String strNodeValue = null;

    try{
        builder = new SAXBuilder(false);
        Document doc = builder.build(new InputSource(new StringReader(strXMLResponse)));

        Element root = doc.getRootElement();  
        Element rootchild = root.getChild(strService); 
        List rootchildren = rootchild.getChildren();

        for (int i=0;i <= rootchildren.size() -1;i++)  
        {  
            Element el = (Element) rootchildren.get(i);  

            if(el.getName().equalsIgnoreCase(strNode)){
                strNodeValue = el.getText();
            }
        }  

    } catch (Exception err) {
        logger.error(err.getMessage(), err);
        throw new ServletException(err.getMessage());
    }

    return strNodeValue;
}
  • 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-16T01:39:25+00:00Added an answer on June 16, 2026 at 1:39 am

    The usual advice for “I want to make a few changes to my XML but keep most of it the same” questions is: start with an identity template (which copies the input to output verbatim), then add specific templates for the things you want to change. The identity template looks like

    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
      </xsl:copy>
    </xsl:template>
    

    Now to handle the <Field> elements you want to create a new element whose name is derived from an attribute of the original Field

    <xsl:template match="Field">
      <xsl:element name="{translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_', 'abcdefghijklmnopqrstuvwxyz')}">
        <xsl:apply-templates select="Value/node()" />
      </xsl:element>
    </xsl:template>
    

    The translate function here will replace all upper-case letters with the equivalent lower-case, and also remove any underscores completely.

    Finally for the FEEDATA and GROSSNETFEES you just need two simple templates

    <xsl:template match="FEEDATA">
      <feedata>
        <xsl:apply-templates select="@*|node()"/>
      </feedata>
    </xsl:template>
    <!-- and likewise for GROSSNETFEES -->
    

    You could combine these two templates into one using the same translate trick if you prefer.

    As for the actual mechanics of doing the transformation, you need to look at the javax.xml.transform package. Seeing as you have code already to parse an XML string into a JDOM tree and extract the element of interest, I would do the XSL transformation in there. Create a single Templates instance at initialization time and store the reference somewhere

    TransformerFactory tf = TransformerFactory.newInstance();
    Source xslSource = new StreamSource(new File(....));
    templates = tf.newTemplates(xslSource);
    

    Now each time you need to do the transformation you can use this templates

    try{
        builder = new SAXBuilder(false);
        Document doc = builder.build(new InputSource(new StringReader(strXMLResponse)));
    
        Element root = doc.getRootElement();  
        Element rootchild = root.getChild(strService); 
        List rootchildren = rootchild.getChildren();
    
        for (int i=0;i <= rootchildren.size() -1;i++)  
        {  
            Element el = (Element) rootchildren.get(i);  
    
            if(el.getName().equalsIgnoreCase(strNode)){
                // do the transformation
                Source s = new JDOMSource(el);
                StringWriter resultWriter = new StringWriter();
                Result r = new StreamResult(resultWriter);
                templates.newTransformer().transform(s, r);
                return resultWriter.toString();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have the following JSON string returned from server: { response:{ imageInstances:{ one:{
I have following string returned from an HTTP request keyverified=yes connected=no now=1347429501 debug=Not connected
I have the following json returned string: [{status:2,id:-1,content:User has entered wrong input,time:1346765646202}] (as you
I have the following long string returned from a SOAP call into a variable,
I have the following string that I want to convert to a presentable XML
I have following JSON string returned to a page. {firstName:Bob,lastName:Gates,department:Tech} I would like to
I have some dates that are returned as the following string: Fri, 13 Aug
Ok, a little new to JSON format.. I have the following JSON string returned
i have an returned data from an php function as the following : data[0]
I have the following json returned to me from an API. sections: { 1:

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.