Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > xslt parsing xml data with '<' invalid character

Reply
Thread Tools

xslt parsing xml data with '<' invalid character

 
 
h_q
Guest
Posts: n/a
 
      01-03-2008
I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I get the following error:

Code: 0xc00ce504
File: ......
Line: ...
Column: ...
A name was started with an invalid character.

The error refers to the '<' found in the string "<20" from my example xml file below (a).

Questions:
(1) Will a docbase/entity solution within my xslt script avoid the "invalid character" error while retaining the '<' in the output .TXT file?
(2) If so, could a forum member modify my example xslt script (b) with the required code?
(3) If neither of the above will work, does someone know how to code a .bat replace of '"<' with '"&lt' (I manually did this replacement and the msxsl call works fine but I'd like to automate this in .bat)?

Below is my project summary:

I have a very basic xml file with the sole element value containing a lot of text data (subset example for <TEST> values):

(a)
<?xml version="1.0"?>
<TEST>
"abcdefgh", "1"
"abcdefgh", "1"
"abcdefgh", "1"
"abcdefgh", "1"

"zzzzzz","yyyyy","xxxx","<20"
"zzzzzz","yyyyy","xxxx","40"
"zzzzzz","yyyyy","xxxx","<20"
</TEST>

Below is the xslt I'm using to create a .txt file from the <TEST> value:
(note that I'm actually using some xpath function for another purpose but to be relevant to my questions above I added <xsl:value-of select="."> to the example below)

(b)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="US-ASCII"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="TEST">
<xsl:copy-of select="@*"/>
<xsl:value-of select="."></xsl:value-of>
<xsl:apply-templates select="*"/>
</xsl:template>
</xsl:stylesheet>

Below is the batch script that calls msxsl:

(c)
------begin .bat-----
for /D %%k in ( C:\test\z\* ) do call :build %%~nk

:build
set _dr=%1
for %%y in ( C:\test\z\*.xml ) do call :build2 %%y

goto :eof

:build2
set _file2=%~pnx1
set _outputtxt=%~pn1.txt
msxsl %_file2% TEST.xslt -o %_outputtxt%

:eof
------end .bat-----

Thanks,
h_q
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid character in base-64 string and invalid postback or callba kevin ASP .Net 0 01-16-2008 09:39 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
[XML::XSLT] empty result while parsing xml file PL Perl Misc 2 12-14-2004 10:24 PM
Invalid XML character Mark XML 5 08-18-2004 01:57 PM
Character reference "&#c" is an invalid XML character cgbusch XML 6 09-02-2003 07:04 PM



Advertisments