Solved

remove a special character from the entire xml

Posted on 2015-01-23
6
77 Views
Last Modified: 2015-01-25
i Have an xml with the following format, the thing is need to replace a character "^" ( with a space or remove it) the character can repeat  in many child nodes, is there a way to remove that special character from whole of the xml (i.e) from root node.


<Details>
                        <Cash>
                                    <TitleLogo> xxxxxx</TitleLogo>
                                    <Title> xxxxxxxxxxx</Title>
                                    <Approval>
                                                <Title>xxx</Title>
                                                <TitleLogo>xxx</TitleLogo>
                                                <Header1>xxx</Header1>
                                                <Header2>xxx</Header2>
                                                <Header3>xxx</Header3>
                                                <Qualified>
                                                            <Person>
                                                                        <Names>xxxxxx</Names>
                                                                        <When>xxxxx</When>
                                                                        <HowMuch>xxxxx</HowMuch>
                                                            </Person>
                                                </Qualified>
                                                <Footer>xxxxxxx</Footer>
                                    </Approval>
                        </Cash>
                       
<Details>
0
Comment
Question by:sri1209
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
Comment Utility
copy the data to a notepad and do a replace for that character to either the space or nothing
copy it back, and save
i would make sure i have a backup first
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
1. I would highly recommend against brendanmeyer's suggestion. One thing that makes XML a good information exchange format is the fact that it has a very reliable encoding mechanism. Opening and saving an XML in notepad most always leads to character encoding problems (unless you are 100% sure you are only using safe characters). If you would do it this way, use an XML editor instead of notepad.

2. If this is in the context of the XSLTs you are developing... make sure you have a template for text() nodes and inside that template do a <xsl:value-of select="translate(., '^', '')"/>
0
 

Author Comment

by:sri1209
Comment Utility
Hi  Geert Bormans,

 i have tried the following but it doesnt translate , i am a little dumb on xslt, could you please let me know if this is correct


 <xsl:template match="node()">
        <xsl:copy>
                        <xsl:value-of select="translate(., '^', '')"/>
        </xsl:copy>
    </xsl:template>

it removes all the nodes,
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
it does not remove all the nodes, it processes the first one at the highest level and pushes out the text content of all nodes

You will need a template for processing the elements and one for processing the text

I can't test right now but

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

would be the template for processing all the element nodes

and this one would be the template for text nodes

<xsl:template match="text()">
                         <xsl:value-of select="translate(., '^', '')"/>
     </xsl:template>

Try the two together in the stylesheet
0
 

Author Comment

by:sri1209
Comment Utility
thank you , it worked. thanks  a lot.
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
welcome
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now