XML to XML transform

Hi all,

I have an XML file in which I just want to change a couple of values.  So, the end result is a new file with exactly the same XML structure.  I am new to XML and XSLT, so I thought I'd start off with something simple; I created an xsl file that would just copy the source directly across without modifying the values (I can do this later, once I have the first bit figured) -

<?

xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:con="http://eviware.com/soapui/config">

<xsl:template match="/">

<xsl:apply-templates/>

</xsl:template>

</xsl:stylesheet>

And, I used the following code to run it -

Dim xslt As New XslCompiledTransform

Try

xslt.Load("XSLTFile.xsl")

xslt.Transform("input.xml", "output.xml")

Catch ex As Exception

End Try

 

The problem is that the output is HTML Encoded, all the angled brackets have been replaced with &lt; and &gt;   ????????!!!!!!!!!!!!

Why?

Thanks

Martin


"Be as smart as you can, but remember that it is always better to be wise than to be smart."

Alan Alda
0
Martin
1/11/2007 12:48:41 AM
asp.net.xml-datasource 7181 articles. 0 followers. Follow

6 Replies
1441 Views

Similar Articles

[PageSpeed] 38

You say that the output is HTML encoded: but how are you displaying the output? If you're throwing it out using a TextBox, then it will be encoded by the TextBox to prevent XSS attacks. Similarly, the grid controls encode output for the same reason.

Or are you saying the output.xml contains encoded content?


Regards

Dave
0
DMW
1/11/2007 1:28:47 AM

Hi
If your text contains a lot of "<" or "&" characters - as program code often does - the XML element can be defined as a CDATA section.
It could be something like this:

<![CDATA[
<You could put whatever here >>
]]>

If this is not what you want pls post your xml content so we can test for you.
Thanks.


NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
1/11/2007 2:58:32 AM

Actually, I just realised what is happenning, the input.xml has a whole bunch of CDATA tags that contain Web Service requests (long story, suffice it to say that the CDATA contains well formed XML).  It is this XML that ends up in the output.xml (as viewed in notepad) with the angle brackets being replaced with &lt;&gt;.

So, if my input.xml file contains -

<test>

<![CDATA[<name>Martin</name>]]>

</test>

The output (using the code and XSL above) is -

&lt;name&gt;Martin&lt;/name&gt;

Any ideas on how to prevent this?

Thanks

Martin

 


"Be as smart as you can, but remember that it is always better to be wise than to be smart."

Alan Alda
0
Martin
1/11/2007 3:44:53 AM

Hey

<xsl:output cdata-section-elements="test"/>

can output CDATA sect.

Hope this helps.


NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
1/11/2007 4:33:54 AM

Hi,

I think that you've put me on the right track.  At least, when I looked it up, the documentation agrees with this being the method to solve my problem.  But, it doesn't seem to work.

My xslt -

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output cdata-section-elements="test "/>

</xsl:stylesheet>

My xml -

  <test>
    <![CDATA[<name>Trevor</name>]]>
  </test>

My output -

    &lt;name&gt;Trevor&lt;/name&gt;

Any ideas?

Thanks

Martin

 


"Be as smart as you can, but remember that it is always better to be wise than to be smart."

Alan Alda
0
Martin
1/11/2007 10:53:15 PM

This one works to me:

  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:con="http://eviware.com/soapui/config">

<xsl:output cdata-section-elements="test"/>
<xsl:template match="*">

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

</xsl:stylesheet>

 
NOTE:If you find my response contains a reference to a third party World Wide Web site, I am providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore,Microsoft cannot make any representations regarding the quality,safety, or suitability of any software or information found there.
__________________________________________________

Sincerely,
Young Fang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Young
1/12/2007 2:39:35 AM
Reply:

Similar Artilces:

XMl to XML
Hello,   I retrieved an XML from the dataset which retrieves data from the table in the database. I need to present the data  in a different structure. Is XSLT the way or are there any other options. please let me know. Thanks!! Yes XSLT is a good choice to convert xml file to other forms. You can take a look at XSLT Tutorial.Sincerely,Young Fang...

XML in, XML out
Hi All (and a happy holiday to those that will get a break), I am trying to read in an XML file of addresses. I need to remove all the address data from the file where code =~ /^000/ (there are none in the example data below). I need to reproduce that data 'as is', so I need to honour the tag structure, although the order of the tags doesn't need to be honoured. I have been trying to use XML::Simple and I had a go with XML::Smart but I haven't been able to get the results I want. My best effort is below (with XML::Simple). There are a couple of differences ...

Transform XML to XML
I've been trying to transform an XML document to another XML document. The original document is very large (6megs) and the application that needs to use it only needs a fraction of the data. I'm trying to take this mother-of-all XML documents and filter out unwanted nodes. I could probably do this very easily with code by running a few XPath Queries against the document, and placing the results in a new document...however...I have an interest in learning how to do this with XSL. In the past, I've done some pretty basic XML to HTML transformation ans that worked out well. This ti...

XML Transform to 1 XML file to another XML File
Hello All  I am a novice programmer. I want to transform 1 xml file to another xml file. I am looking for a example code where user will select source xml file and create another xml file in different file with different fields with some default validation of parsing date and default values.  Can anyone help me or let me know any available source code in C#/ASP.Net?  Ms Disha I am assuming you know xslt, if not, you would have to go look at that.  But if you do, then this document will help you out http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=...

XSLT to transform XML into XML in VB.NET
Hello. I need some help with XSLT. We have an XML coming in and I need to transform this XML to a format that we use using XSLT so that future changes in the incoming file are easy to change in the XSLT rather than changing the VB code.This is the sample input file  <MemberReports xsi:schemaLocation="http://developreports/myreport/v1/report.xsd"> <DateCreated>2006-04-15</DateCreated> <MemberReport> <MemberOrganization>MemberOrganization</ReportingOrganization> <Member> <Name> ...

XML::Parser XML::DOM XML::XSLT
------_=_NextPart_001_01C6E0D0.3E27D77A Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Hi Craig and fellow VMS Perlers, You last wrote about this Fri 3/16/2001 11:24 AM, not counting your very helpful comments on Eisner/Decuserve more recently. One of my colleagues sent me an email requesting that I make XML::XSLT=20 available on VMS. perl 5.8.6, VMS 7.3-2, DECC 7.1 latest ACRTL (version 3) on Alpha XML::XSLT (version 0.48) depends on XML::Parser (version 2.34). This depends on expat (version 2.0.0). I built expat a...

sort xml in xml
Hi, How I can sort xml file in xml with VB.NetThanks,<?xml version="1.0" encoding="ISO-8859-1" ?>  <Liste>   <Form Famille="Administration" idXhtml="" idOffice="31574" nom="ADM" desc="" />   <Form Famille="Admini" idXhtml="" idOffice="31708" nom="ADM- 54 (2000)" desc="" />   <Form Famille="communication" idXhtml="" idOffice="31709" nom="ADM- 133 (2000)" desc="" />   <Form Famille="Admini" idXhtml="" idOffice="31710" nom="ADM- 9 (2000)" desc="" />   <Form Famille="Admini" idXhtml="" idOffice="31711" no...

How to select Xml as Xml?
If I select Xml nodes like this from sql server; select xmlData.query('//Field[@F = "True"]') as extendedInfo from.... ..how to loop through the items in C#? I can't cast it to a System.Xml.XmlNodeList..? You can use the XmlDocument class.  There's a Load method and a LoadXml method.  One of these should get you what you want, after which you can select nodes as you need.C# <---> VB.Net Translator mm8: If I select Xml nodes like this from sql server; select xmlData.query('//Field[@F = "True"]') as extendedInfo from.... ...

XML datasource from external website XML file
Hi all i need to extract some data into a page on my website, but the xml file is on different web server, not in our bunch, but out in the ether.is it possible to use this file as a datsource directly, or is there some security issue, and i have to grab it and use it locally...??? the file has been put somewhere it can be accessed with a web browseras this file changes on a daily basis, i would also like to automate the daily retrieval, i'm assuming this is something not too simple either. as you would need a service or something to fire up at a specific time each day?! any he...

reading data from xml service or xml datasource
Hi, I'm trying to figure out a way to import data (but not export to, I'm just trying to get their news section) from an external db (SqlServer 2000 or 2005) to a gridview and detailsview on my site (resides at a web host). I spoke to the organisation that owns the external db and they are willing to look into several solutions, whitout giving out their db password etc. Not suprisingly, I was reccomended using a web service. However, I believe I need to install stuff in order to enable one, and so, it won't be able for me (I guess), because of my web host's limitations. Instead, I am now t...

Transform XML to XML (DataSet) using XSLT
Hi. I need help to transform a XML-dokument to a NEW XML-dokument or a DataSet using XSLT transformation. How do tranform this? XmlDocument docXml2 = new XmlDocument(); docXml.Load("xmlurl.xml"); XslTransform docXsl = new XslTransform(); docXsl.Load(Server.MapPath("Myxsl.xsl")); **** docXsl.Transform(docXml,null, ?????????); **** ????????? : needs to be at XML-dokument or at Dataset \Torben DocXml2.Load(docXsl.Transform(docXml,null)); Oleg [XML MVP, MCPD]XmlLab.Net | http://blog.tkachenko.com HI I am still getting a error:...

Transforming XML into XML, creating a temporary file.
I've some XML which is formatted like such:1 <level1 name="category">2 <level2 name="subcategorya">3 <level3 name="item1" att="stuff" />4 </level2>5 <level2 name="subcategoryb">6 <level3 name="item2" att="stuff" />7 </level2>8 </level1>What I would like to do is transform it into something like this: 1 <category>2 <subcategorya>3 <item1 att="stuff" />4 </subc...

Problem loading an xml string containing xml data into XML document
 Hi all,I have a problem loading an xml string containing xml response data returned by other server(spatial server) into XML document some times becoz the returned xml response contains special chars like <, >, ', etc.Is there any way to parse this XML response string before loading into XML document. Hi Bharath, if you can't find a ready made one you can write one yourself. Parse the string that you get for the elements that it would contain and inject the CDATA element between them to allow special character. example if you have a string <childNode>This con...

Problems writing to an XML file
I'm brand new to using XML (in fact this is my first project), so bear with me, I may need a little hand-holding. I'm trying to create a page which simply adds data to an existing xml file. Ultimately it will add the data from a form, but to keep things simple, I've been simply using pre-defined values. Originally I was able to get the script to write the xml exactly as I needed, however it would simply overwrite the existing file every time it was accessed. This is unacceptable, as it will be used to add data to one file, sort of like a mini database. So after much pain and gnashi...

Web resources about - XML to XML transform - asp.net.xml-datasource

Möbius transform - Wikipedia, the free encyclopedia
Weisstein, Eric W. , " Möbius Transform " from MathWorld . Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit ...

Amir Arjomand-A Regime Facing a Legitimacy Crisis Will Transform Dialogue Over a Drying Lake Into A Matter ...
Banooye Sabz hat eine Notiz mit dem Titel Amir Arjomand-A Regime Facing a Legitimacy Crisis Will Transform Dialogue Over a Drying Lake Into A ...

➚ Trevor sez, "Friday and Saturday night, design collective The Mission Business transforms Toronto's ...
Trevor sez, "Friday and Saturday night, design collective The Mission Business transforms Toronto's Evergreen Brick Works into an end of the ...

35 Quotes To Transform Yourself Into A Leader
Leadership is a tricky thing. Is it innate or learned? Who needs it the most? What traits define a strong leader?The fact of the matter is that ...

Voicy Helium Voice Changer Recorder - Transform and change your video.s into funny chipmunk effects on ...
Get Voicy Helium Voice Changer Recorder - Transform and change your video.s into funny chipmunk effects on the App Store. See screenshots and ...

Patent application shows Apple Watch band that transforms into a case, stand and Mac accessory
... it to do much more than simply secure the Apple Watch on your wrist. By using a careful arrangement of magnet orientations, the band can transform ...

Ex-Googler Reveals How A.I. Will Transform Robots
Friday afternoon at the Venetian hotel in Las Vegas I sat in on a discussion on the future of robots and how they will be made better by artificial ...

The owner of CNN and TNT wants to transform commercial breaks into 3-minute-long native ads
Turner Broadcasting — which owns TV networks including CNN, TNT, and Cartoon Network — has a plan to transform its commercial breaks to make ...

ENGAGE.cx And Cisco Transform the $2.2T Digital-Physical Divide with Out-of ...
ENGAGE.cx And Cisco Transform the $2.2T Digital-Physical Divide with Out-of ... Business Wire (press release) NEW YORK(BUSINESS WIRE)Unveiled ...

Lumiere London transforms city into kaleidoscope of color
Light festival turns the British capital into a cathedral of the absurd and other-worldy, equal parts "Alice in Wonderland" and "Avatar"

Resources last updated: 1/18/2016 10:32:06 PM