Easy xml file save question
-
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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 theXslTransform.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
-
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 theXslTransform.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
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
-
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 theXslTransform.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
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
-
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
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