Solved

regulate xml

Posted on 2014-04-03
6
187 Views
Last Modified: 2014-04-05
Dear all,
Useing C# I need to change this xml :
 
<SDic Lang='En'>
	<GivenWord>freund's adjuvant</GivenWord>
	<word value='freund's adjuvant'>
		<POS type="undefined">
			<MeaningList>
				<DescriptionAR>xxxx</DescriptionAR>
			</MeaningList>
		</POS>
	</word>
</SDic>

Open in new window


TO

<SDic Lang="En">
	<GivenWord>freund&apos;s adjuvant</GivenWord>
	<word value="freund&apos;s adjuvant">
		<POS type="undefined">
			<MeaningList>
				<DescriptionAR>xxxx</DescriptionAR>
			</MeaningList>
		</POS>
	</word>
</SDic>

Open in new window


( I need to change ' to be " for Attribute values , and change any ' to &apos; for the values )


Thanks
0
Comment
Question by:ethar1
  • 3
  • 3
6 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
Using regular expression, you would first search for:
"([A-Za-z])'([A-Za-z])"

Open in new window

and replace with
$1&apos;$2

Open in new window

After that, simply replace all remaining ' with "

HTH,
Dan
0
 

Author Comment

by:ethar1
Comment Utility
could please give code sample? thanks,
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
Assuming you have your xml in a string called xmlString:
xmlString = Regex.Replace(xmlString, @"([A-Za-z])'([A-Za-z])", "$1&apos;$2");
xmlString = Regex.Replace(xmlString, @"'", "\"");

Open in new window

You can do a regular replace for the second line, but looks cooler this way :)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:ethar1
Comment Utility
Dan,
This
xmlString = Regex.Replace(xmlString , @"'", "\"");

change ' to \"

It should changed to "
0
 

Author Comment

by:ethar1
Comment Utility
I need the  solution to differentiate
between

' as opener+closing for attribute

Open in new window


and
' as apostrophe = value of attribute 

Open in new window

0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
Comment Utility
That's what the solution does.

The first searches for all sequences of type letter'letter and changes them to &apos;

The second changes the remaining ' to ". Or it should :) If the escape is not needed, then the second line should be:

xmlString = Regex.Replace(xmlString, @"'", """);

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

9 Experts available now in Live!

Get 1:1 Help Now