On Thu, 18 Mar 2004 16:43:29 +0100, Jeroen van den Bos (DT) <[EMAIL PROTECTED]> wrote:
>Chad, > >Thanks! That works. What I wonder though, why is it not valid XML? Straight from the big dogs, http://www.w3.org/TR/2004/REC-xml11- 20040204/#syntax. >Should I just write the unescaped characters in my XML files instead to >make them valid (the XML I write is in UTF8)? It depends. Did you want to get rid of the & because you were passing on the xml to some home-grown or other parser that does not understand the escape sequence of characters &? Are you trying to build valid xml without using the System.XML namespace or is this just an eye-candy thing when viewing the xml? If you are using System.Xml to build the doc and System.Xml to read the doc (or other compliant parsers), then absoulutely just use the XmlDocument::Save() and leave in the &. > >-Jeroen > >-----Original Message----- >From: Moderated discussion of advanced .NET topics. >[mailto:[EMAIL PROTECTED] On Behalf Of Chad M. Gross >Sent: donderdag 18 maart 2004 15:24 >To: [EMAIL PROTECTED] >Subject: Re: [ADVANCED-DOTNET] Getting escaped characters into an >XmlElement > >Sure there is a way around it: > > StreamWriter sw = File.CreateText >(@"C:\temp\out.xml"); > sw.Write(doc.OuterXml.Replace("&", "&")); > sw.Close(); > >This output of course is not valid XML. Unfortunately though, you can >actually load this output document into an XMLDocument in .NET. But if >you loaded this unvalid doc and then added another node to it and tried >to >save it off, the output is now hosed up. Take a look at the below snip: > > XmlDocument doc = new XmlDocument(); > XmlNode docElem = doc.AppendChild >(doc.CreateElement("DocElement")); > docElem.AppendChild(doc.CreateElement >("SubElement")).InnerText = "ԵԽ"; > XmlNode nd = doc.ChildNodes[0].ChildNodes[0]; > > StreamWriter sw = File.CreateText >(@"C:\temp\out.xml"); > sw.Write(doc.OuterXml.Replace("&", "&")); > sw.Close(); > > XmlDocument doc2 = new XmlDocument(); > doc2.Load(@"C:\temp\out.xml"); > doc2.DocumentElement.AppendChild(doc2.CreateElement >("SubElement2")).InnerText = "ԵԽ"; > doc2.Save(@"C:\temp\out2.xml"); > >Chad > >On Thu, 18 Mar 2004 09:31:26 +0100, Jeroen van den Bos (DT) ><[EMAIL PROTECTED]> wrote: > >>Hi all, >> >>I'm reading data from a device and want to store the result in Xml. For >>instance, I'd like to get this in my Xml output: >> >><tag>ԵԽ</tag> >> >>If I write this to the InnerText of a "tag"-XmlElement, the >&-characters >>get translated to &. Is there any way around this? >> >>Thanks for any help! >>-Jeroen >> >>=================================== >>This list is hosted by DevelopMentor(r) http://www.develop.com >>Some .NET courses you may be interested in: >> >>NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles >>http://www.develop.com/courses/gaspdotnetls >> >>View archives and manage your subscription(s) at >http://discuss.develop.com > >=================================== >This list is hosted by DevelopMentor(r) http://www.develop.com >Some .NET courses you may be interested in: > >NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles >http://www.develop.com/courses/gaspdotnetls > >View archives and manage your subscription(s) at >http://discuss.develop.com > >=================================== >This list is hosted by DevelopMentorŪ http://www.develop.com >Some .NET courses you may be interested in: > >NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles >http://www.develop.com/courses/gaspdotnetls > >View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com