Solved

regulate xml

Posted on 2014-04-03
6
189 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
ID: 39974457
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
ID: 39974525
could please give code sample? thanks,
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39974535
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

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

change ' to \"

It should changed to "
0
 

Author Comment

by:ethar1
ID: 39974616
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
ID: 39974752
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

19 Experts available now in Live!

Get 1:1 Help Now