String values w/double quotation marks in an XML attribute?

String values w/double quotation marks in an XML attribute?

Post by rh » Wed, 04 Dec 2002 05:35:46



Hi,

I was wondering how to go about saving a String value that has double
quotation marks in an XML attribute. In my XML files, attribute values are
surrounded by double quotation marks. For example <Person FirstName="Pip"/>

Thanks in advance.

 
 
 

String values w/double quotation marks in an XML attribute?

Post by Dare Obasanj » Wed, 04 Dec 2002 07:03:42


Use the &qout; entity to represent quotation marks.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


> Hi,

> I was wondering how to go about saving a String value that has double
> quotation marks in an XML attribute. In my XML files, attribute values are
> surrounded by double quotation marks. For example <Person
FirstName="Pip"/>

> Thanks in advance.


 
 
 

String values w/double quotation marks in an XML attribute?

Post by Martin Honne » Wed, 04 Dec 2002 07:06:42



> Hi,

> I was wondering how to go about saving a String value that has double
> quotation marks in an XML attribute. In my XML files, attribute values are
> surrounded by double quotation marks. For example <Person FirstName="Pip"/>

If you edit by hand use &quot;
   <gods anAttribute="&quot;quoted text&quot;"/>
I don't know how you are manipulating the XML document, if you use .NET
for instance and the DOM then you can set the attribute value and the
document will be serialized with the entity reference:

using System.Xml;

class Test20021202 {
   public static void Main () {
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.AppendChild(xmlDocument.CreateElement("gods"));
     xmlDocument.DocumentElement.SetAttribute("anAttribute", "\"quoted
text\"");
     System.Console.WriteLine(xmlDocument.OuterXml);
   }

Quote:}