Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XML to TXT [Thread Next] Re: XML to TXTTo: 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
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
