Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML to TXT

From: "sloan" <sloan@-----.--->
To: NULL
Date: 11/11/2009 9:11:00 AM


I'm not sure if this is helpful.

But if you want to get the xml (mostly) the way it was........but have the 
ability to update a few things......this is a (not yet proven) idea:
Well, it works as I have it below, but I don't know if it meets your need.


The below example will "copy" the xml to new xml, with one slight override.
The original WhoAmI (value) of DefaultWhoAmI will be replaced with a new 
value of NOTDefaultWhoAmI.

Check the URL in the xsl comments for where I discovered this trick.

Save the xml as "myxml.xml" and the xsl as "myxsl.xsl".
The create a vbs file called "transform.vbs", and put the code I have below 
in it.
Run transform.vbs and you should get a file called newStuff.xml.




------START XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>


  <appSettings>
    <add key ="WhoAmI" value="DefaultWhoAmI"/>
    <add key ="ThisStays" value="TheSame"/>
  </appSettings>


 <someOtherElement>
  <abc>123</abc>
  <def>234</def>
  <ghi>345</ghi>
 </someOtherElement>

</configuration>
----------------------END XML


--------START XSL

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

  <!--http://adeneys.wordpress.com/2009/04/17/multi-environment-config/-->

  <xsl:output method="xml" indent="yes"/>

  <xsl:template 
match="/configuration/appSettings/add[@key='WhoAmI']/@value">
    <xsl:attribute name="value">NOTDefaultWhoAmI</xsl:attribute>
  </xsl:template>



    <!-- Default templates to match anything else -->
    <xsl:template match="@*">
      <xsl:copy/>
    </xsl:template>

    <xsl:template match="node()">
      <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:apply-templates/>
      </xsl:copy>
    </xsl:template>
  </xsl:stylesheet>


--------END XSL



Start a vbs app to make the transformation
(call it transform.vbs or something)
-------------- START .VBS code

Option Explicit


Dim xmldoc 'As New MSXML2.DOMDocument40
set xmldoc = CREATEOBJECT("MSXML2.DOMDocument.4.0")
xmldoc.async = False
xmldoc.Load ".\myxml.xml"



Dim xsldoc  'As New MSXML2.DOMDocument40
set xsldoc = CREATEOBJECT("MSXML2.DOMDocument.4.0")
xsldoc.async = False
xsldoc.Load ".\myxsl.xsl"




dim result
result = xmldoc.transformNode(xsldoc)



'Dim XMLDoc
'Dim XSLDoc
'Set XMLDoc = WScript.CreateObject("MSXML.DOMDocument")
'XMLDoc.load WScript.Arguments(0)
'Set XSLDoc = WScript.CreateObject("MSXML.DOMDocument")
'XSLDoc.load WScript.Arguments(1)
Dim OutFile
Dim FSO
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set OutFile = FSO.CreateTextFile(".\newStuff.xml")
'OutFile.Write XMLDoc.transformNode(XSLDoc)
outfile.write result
OutFile.Close




"Tom Woods" <twoods@g...> wrote in message 
news:enyA5xQTKHA.764@T......
> Is there a simple way to take a Xml.XmlDocument and save it as a TXT file 
> with formatting?
>
> Thanks,
> Tom
>
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent