Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. XmlWriter

XmlWriter

Scheduled Pinned Locked Moved WPF
csharplinqsysadminxmlquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ranger49
    wrote on last edited by
    #1

    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.

    R 1 Reply Last reply
    0
    • R Ranger49

      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.

      R Offline
      R Offline
      Ranger49
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      0
      • R Ranger49

        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.

        R Offline
        R Offline
        Ranger49
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • R Ranger49

          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

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          R 1 Reply Last reply
          0
          • M Mark Salsbery

            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:

            R Offline
            R Offline
            Ranger49
            wrote on last edited by
            #5

            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.

            M 1 Reply Last reply
            0
            • R Ranger49

              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.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              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:

              R 1 Reply Last reply
              0
              • M Mark Salsbery

                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:

                R Offline
                R Offline
                Ranger49
                wrote on last edited by
                #7

                Thanks... I will study this. Ranger

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups