?
Solved

remove a special character from the entire xml

Posted on 2015-01-23
6
Medium Priority
?
86 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 40567906
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
ID: 40567923
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
ID: 40568267
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
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 40568441
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
ID: 40568541
thank you , it worked. thanks  a lot.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40568918
welcome
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 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