Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2006

Tip: Looking for answers? Try searching our database.

" and ' is not XML-ified

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnny Ljunggren - 06 Jul 2006 08:39 GMT
Hello all

Just noticed that a testprogram I've made creates a non-conforming XML
file. Here's the code (C#) and output:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using(XmlWriter writer = XmlWriter.Create("xmltest.xml",settings))
{
  // Write XML data.
  writer.WriteStartElement("xmltest");
  string tmp = "< > & ' \"";
  writer.WriteElementString("test",tmp);
  writer.WriteEndElement();
  writer.Flush();
}

output:
<?xml version="1.0" encoding="utf-8"?>
<xmltest>
  <test>&lt; &gt; &amp; ' "</test>
</xmltest>

How come ' and " is not translated to &apos; and &quot;?

Also, I tried to manually translate ' and " but then XmlWriter will
translate the extra & and thus gives &amp;apos; etc.

Any pointers to this would be greatly appreciated.

regards
Johnny Ljunggren
Bjoern Hoehrmann - 06 Jul 2006 09:05 GMT
* Johnny Ljunggren wrote in microsoft.public.dotnet.xml:
>Just noticed that a testprogram I've made creates a non-conforming XML
>file.

The characters ' and " need to be escaped if and only if they are
supposed to occur in an attribute value that is delimited using the
same character, so name='Teal'C' is not allowed, but name="Teal'C"
is. So the content is fine, and I would suggest to not worry about
this.
Signature

Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Johnny Ljunggren - 06 Jul 2006 09:54 GMT
>> Just noticed that a testprogram I've made creates a non-conforming XML
>> file.

> The characters ' and " need to be escaped if and only if they are
> supposed to occur in an attribute value that is delimited using the
> same character

Thanks!

Johnny L

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.