Solved

remove a special character from the entire xml

Posted on 2015-01-23
6
84 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML filtering Windows Event Viewer 10 89
XML response optional elements 12 78
Help needed with Powershell  XML to MySQL 5 87
ASP Classic - Read XML File inner content 10 69
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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, …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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