Solved

regulate xml

Posted on 2014-04-03
6
193 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 35

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 35

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
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!

 

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 35

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

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…
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
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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