Solved

regulate xml

Posted on 2014-04-03
6
197 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
[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
  • 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

717 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