?
Solved

regulate xml

Posted on 2014-04-03
6
Medium Priority
?
198 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 

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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 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