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. C#
  4. Easy xml file save question

Easy xml file save question

Scheduled Pinned Locked Moved C#
questionxml
9 Posts 2 Posters 1 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.
  • L Offline
    L Offline
    lsugirljte
    wrote on last edited by
    #1

    I know this is an easy one but I can't find any examples. I have a xml file that I transform (via xslt) and I need to save it. How? string ls_xml; XmlDocument doc = new XmlDocument(); Xml output_xml = new Xml(); ls_xml = GetXMLString(); // returns xml string doc.LoadXml(ls_xml); output_xml.Document = doc; output_xml.TransformSource = "menu.xslt"; I can look at the output_xml and it's exactly what I want but in a web.sitemap file. How do I save it without using a xmlwriter to parse through the entire xml file? That seems a little redundent since it's in the desired format already. Thanks, Jessica

    J 1 Reply Last reply
    0
    • L lsugirljte

      I know this is an easy one but I can't find any examples. I have a xml file that I transform (via xslt) and I need to save it. How? string ls_xml; XmlDocument doc = new XmlDocument(); Xml output_xml = new Xml(); ls_xml = GetXMLString(); // returns xml string doc.LoadXml(ls_xml); output_xml.Document = doc; output_xml.TransformSource = "menu.xslt"; I can look at the output_xml and it's exactly what I want but in a web.sitemap file. How do I save it without using a xmlwriter to parse through the entire xml file? That seems a little redundent since it's in the desired format already. Thanks, Jessica

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Hi Jessica Does

      doc.Save("myfile.xml");

      fit the bill?

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      L 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Hi Jessica Does

        doc.Save("myfile.xml");

        fit the bill?

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        L Offline
        L Offline
        lsugirljte
        wrote on last edited by
        #3

        No. That will save the original xml document file. and I need to save the xml after the transformation. I want to save the output_xml (type xml, not xmldocument) without parsing through the entire xml.

        Thanks, Jessica

        J 1 Reply Last reply
        0
        • L lsugirljte

          No. That will save the original xml document file. and I need to save the xml after the transformation. I want to save the output_xml (type xml, not xmldocument) without parsing through the entire xml.

          Thanks, Jessica

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Ok, now I think I understand. You want to save output_xml to a file, is that right? If so, can you simply do

          File.WriteAllText("myFile.xml", output_xml.DocumentContent);

          ?

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          L 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            Ok, now I think I understand. You want to save output_xml to a file, is that right? If so, can you simply do

            File.WriteAllText("myFile.xml", output_xml.DocumentContent);

            ?

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            L Offline
            L Offline
            lsugirljte
            wrote on last edited by
            #5

            OOhh... that gets me so much closer. But my DocumentContent is blank. I looked at other properties but Document.InnerXML contains the initial xml (not post transform). I know the transform is happening because I can add an control to the form and see the transform xml. I just don't know how to access it at run time to save to a file.

            Thanks, Jessica

            J 1 Reply Last reply
            0
            • L lsugirljte

              OOhh... that gets me so much closer. But my DocumentContent is blank. I looked at other properties but Document.InnerXML contains the initial xml (not post transform). I know the transform is happening because I can add an control to the form and see the transform xml. I just don't know how to access it at run time to save to a file.

              Thanks, Jessica

              J Offline
              J Offline
              Judah Gabriel Himango
              wrote on last edited by
              #6

              Sounds like you need to do the transform yourself on the initial XML. Can you either create a new transform or access the Xml.Transform property, then transform the initial XML using the XslTransform.Transform method?

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              L 2 Replies Last reply
              0
              • J Judah Gabriel Himango

                Sounds like you need to do the transform yourself on the initial XML. Can you either create a new transform or access the Xml.Transform property, then transform the initial XML using the XslTransform.Transform method?

                Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                L Offline
                L Offline
                lsugirljte
                wrote on last edited by
                #7

                I thought that was what I was doing in my initial code I posted. string ls_xml; XmlDocument doc = new XmlDocument(); Xml output_xml = new Xml(); ls_xml = GetXMLString(); // returns xml string doc.LoadXml(ls_xml); output_xml.Document = doc; output_xml.TransformSource = "menu.xslt";

                Thanks, Jessica

                1 Reply Last reply
                0
                • J Judah Gabriel Himango

                  Sounds like you need to do the transform yourself on the initial XML. Can you either create a new transform or access the Xml.Transform property, then transform the initial XML using the XslTransform.Transform method?

                  Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  L Offline
                  L Offline
                  lsugirljte
                  wrote on last edited by
                  #8

                  got it. Thanks for your help. I thought that would be easier but it wasn't.:) doc.LoadXml(ls_xml); string sitemapxslFile = MapPath("menu_sitemap.xslt"); string tempfile = MapPath("jte.sitemap"); StringBuilder sb = new StringBuilder(); TextWriter tw = new StringWriter(sb); XslTransform xsl = new XslTransform(); xsl.Load(sitemapxslFile); //load xsl file xsl.Transform(doc, null, tw, null); //does transformation XmlDocument ret = new XmlDocument(); ret.LoadXml(sb.ToString()); ret.Save(tempfile);

                  Thanks, Jessica

                  J 1 Reply Last reply
                  0
                  • L lsugirljte

                    got it. Thanks for your help. I thought that would be easier but it wasn't.:) doc.LoadXml(ls_xml); string sitemapxslFile = MapPath("menu_sitemap.xslt"); string tempfile = MapPath("jte.sitemap"); StringBuilder sb = new StringBuilder(); TextWriter tw = new StringWriter(sb); XslTransform xsl = new XslTransform(); xsl.Load(sitemapxslFile); //load xsl file xsl.Transform(doc, null, tw, null); //does transformation XmlDocument ret = new XmlDocument(); ret.LoadXml(sb.ToString()); ret.Save(tempfile);

                    Thanks, Jessica

                    J Offline
                    J Offline
                    Judah Gabriel Himango
                    wrote on last edited by
                    #9

                    Glad you got it working. Too bad there doesn't seem to be an easier way. I'm not familiar with the Xml web control as I don't do web development, so FWIW, there may be an easier way I'm just not familiar with. If you really do need an easier way, you might want to post this question in the ASP.NET forum.

                    Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                    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