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 TryThe problem is that the output is HTML Encoded, all the angled brackets have been replaced with < and > ????????!!!!!!!!!!!!
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 <>.
So, if my input.xml file contains -
<test>
<![CDATA[<name>Martin</name>]]>
</test>
The output (using the code and XSL above) is -
<name>Martin</name>
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 |
![]() |
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 |
![]() |
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 -
<name>Trevor</name>
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 |
![]() |
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 |
![]() |