XmlWriter
-
using System; using System.Text; using System.Collections.Generic; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Xml; using System.Xml.Linq; namespace SilverlightApplication1 { public partial class Page : UserControl { public Page() { InitializeComponent(); StringBuilder sb = new StringBuilder(); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Indent = true; using (XmlWriter xw = XmlWriter.Create(sb, xws)) { XDocument xd = new XDocument(
I tried with this code to wite an XML file to the server (local host). But that VWDExpress doesn't see the XmlWriterSettings and XmlWriter. I think I am using the wrong references. Can anybody tell me in what reference XmlWriterSettings and XmlWriter can be found? Thanks, Ranger. PS, If anybody can get me a sample project I would appreciate it. -
using System; using System.Text; using System.Collections.Generic; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Xml; using System.Xml.Linq; namespace SilverlightApplication1 { public partial class Page : UserControl { public Page() { InitializeComponent(); StringBuilder sb = new StringBuilder(); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Indent = true; using (XmlWriter xw = XmlWriter.Create(sb, xws)) { XDocument xd = new XDocument(
I tried with this code to wite an XML file to the server (local host). But that VWDExpress doesn't see the XmlWriterSettings and XmlWriter. I think I am using the wrong references. Can anybody tell me in what reference XmlWriterSettings and XmlWriter can be found? Thanks, Ranger. PS, If anybody can get me a sample project I would appreciate it. -
I just discovered that I hadn't included a using System.Xml; line in the header. But where do you specify the filename of the xml-file you are trying to save? Ranger.
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Xml; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.IO; namespace LinqToXmlSilverlight090322 { public partial class Page : UserControl { public Page() { InitializeComponent(); StringBuilder sb = new StringBuilder("test.xml", 10); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Indent = true; using (XmlWriter xw = XmlWriter.Create(sb, xws)) { XDocument xd = new XDocument( new XElement("MyFractals", new XElement("first", new XAttribute("range", "1,5"), new XAttribute("startRe", "1,0"), new XAttribute("startIm", "-0,7"), new XAttribute("startColor", "100") ), new XElement("second", new XAttribute("range", "0,5"), new XAttribute("startRe", "0,105"), new XAttribute("startIm", "-0,6"), new XAttribute("startColor", "160") ), new XElement("third", new XAttribute("range", "0,75"), new XAttribute("startRe", "0,5"), new XAttribute("startIm", "0,204"), new XAttribute("startColor", "60") ) ) ); xd.Save(xw); } using (XmlReader reader = XmlReader.Create(new StringReader(sb.ToString()))) { XDocument xd2 = XDocument.Load(reader); XElement rt = xd2.Element(XName.Get("MyFractals")); var xyz = from e in rt.Elements() select e; //foreach (XElement x in xyz) } } } }
Why doesn't this work? There is no test.xml file created and when the program tries to open the xml file (which I manually placed) I get -
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Xml; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.IO; namespace LinqToXmlSilverlight090322 { public partial class Page : UserControl { public Page() { InitializeComponent(); StringBuilder sb = new StringBuilder("test.xml", 10); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Indent = true; using (XmlWriter xw = XmlWriter.Create(sb, xws)) { XDocument xd = new XDocument( new XElement("MyFractals", new XElement("first", new XAttribute("range", "1,5"), new XAttribute("startRe", "1,0"), new XAttribute("startIm", "-0,7"), new XAttribute("startColor", "100") ), new XElement("second", new XAttribute("range", "0,5"), new XAttribute("startRe", "0,105"), new XAttribute("startIm", "-0,6"), new XAttribute("startColor", "160") ), new XElement("third", new XAttribute("range", "0,75"), new XAttribute("startRe", "0,5"), new XAttribute("startIm", "0,204"), new XAttribute("startColor", "60") ) ) ); xd.Save(xw); } using (XmlReader reader = XmlReader.Create(new StringReader(sb.ToString()))) { XDocument xd2 = XDocument.Load(reader); XElement rt = xd2.Element(XName.Get("MyFractals")); var xyz = from e in rt.Elements() select e; //foreach (XElement x in xyz) } } } }
Why doesn't this work? There is no test.xml file created and when the program tries to open the xml file (which I manually placed) I getRanger49 wrote:
There is no test.xml file created
The XmlWriter you are using should be writing the XML to the StringBuilder, not to a file. In Silverlight 2, the only access you have to the user's local hard disk is using Isolated Storage: How to: Save XMLWriter Content to Isolated Storage[^]
Ranger49 wrote:
I get an error message saying 'line 1 character 1 illegal character'.
Probably because your StringBuilder has "test.xml" at the beginning of its contents, which isn't valid XML. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Ranger49 wrote:
There is no test.xml file created
The XmlWriter you are using should be writing the XML to the StringBuilder, not to a file. In Silverlight 2, the only access you have to the user's local hard disk is using Isolated Storage: How to: Save XMLWriter Content to Isolated Storage[^]
Ranger49 wrote:
I get an error message saying 'line 1 character 1 illegal character'.
Probably because your StringBuilder has "test.xml" at the beginning of its contents, which isn't valid XML. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Ok, I see... What I would want to do is write an XML file with data to the server where the Silverlight application is situated. Is this possible at all? Or is the only option Isolated Storage on the computer of the person who is viewing the Silverlight application? Thanks! Ranger.
-
Ok, I see... What I would want to do is write an XML file with data to the server where the Silverlight application is situated. Is this possible at all? Or is the only option Isolated Storage on the computer of the person who is viewing the Silverlight application? Thanks! Ranger.
Silverlight runs entirely on the client side. To write to a server, you'll need to send it to the server. Here's some info on ways to do that: Silverlight Networking and Communication[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Silverlight runs entirely on the client side. To write to a server, you'll need to send it to the server. Here's some info on ways to do that: Silverlight Networking and Communication[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: