473,738 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xslt parsing xml data with '<' invalid character

1 New Member
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)
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <TEST>
  3. "abcdefgh", "1"
  4. "abcdefgh", "1"
  5. "abcdefgh", "1"
  6. "abcdefgh", "1"
  7.  
  8. "zzzzzz","yyyyy","xxxx","<20"
  9. "zzzzzz","yyyyy","xxxx","40"
  10. "zzzzzz","yyyyy","xxxx","<20"
  11. </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)
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="text" encoding="US-ASCII"/>
  3.   <xsl:template match="@*|node()">
  4.      <xsl:copy>
  5.          <xsl:apply-templates select="@*|node()"/>
  6.      </xsl:copy>
  7.    </xsl:template>
  8.   <xsl:template match="TEST">
  9.      <xsl:copy-of select="@*"/>
  10.      <xsl:value-of select="."></xsl:value-of>
  11.      <xsl:apply-templates select="*"/>
  12.    </xsl:template>
  13. </xsl:stylesheet>
Below is the batch script that calls msxsl:

(c)
Expand|Select|Wrap|Line Numbers
  1. ------begin .bat-----
  2. for /D %%k in ( C:\test\z\* ) do call :build %%~nk
  3.  
  4. :build
  5. set _dr=%1
  6. for %%y in ( C:\test\z\*.xml ) do call :build2 %%y
  7.  
  8. goto :eof
  9.  
  10. :build2
  11. set _file2=%~pnx1
  12. set _outputtxt=%~pn1.txt
  13. msxsl %_file2% TEST.xslt -o %_outputtxt%
  14.  
  15. :eof
  16. ------end .bat-----
Thanks,
h_q
Jan 4 '08 #1
1 3816
jkmyoung
2,057 Recognized Expert Top Contributor
There's nothing wrong with the rest of the code, just the 'xml'. Is it possible to change the service sending the incoming data so that it is xml? eg escape < as &lt;

If not, I wish you good luck with your script. I suggest using something like perl or php to escape the proper portions of your document.
Jan 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6005
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the cdata sections will be echoed an not the element names as in the original example. In the cdata sections of my XML file I have terms like this:
13
3678
by: Tjerk Wolterink | last post by:
Hello i've an xsl stylesheet that must support xhtml entities, my solution: ---- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE xsl:stylesheet > <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
2159
by: Rob Archibald | last post by:
I have a back end system that passed data to me in tabular XML format so that it can be easily loaded into a Data Dynamics SharpGrid. The native format for data in SharpGrid is like the following: <Data count=1> <row col1="My Data" col2="More Data" col3="Even more data" /> </Data> The problem with this format is that the only way xml can be sent in one of these attributes is to replace all < with &lt; and > with &gt;. This is
6
2875
by: David Walker | last post by:
Hi, I have an XML file created by a third party in which an element with a simple content model has a text value consisting of 2 parts separated by a colon, like this <link>machine:port</link> Is XSLT capable of parsing the value of a <link> element, to separately extract the portions before and after the colon?
6
1861
by: Vincent van Beveren | last post by:
Hey everyone, I try to insert a special character into my HTML using the DOM. I do this by the following piece of code: document.getElementById('space'). appendChild(document.createTextNode('&lt;')); Can anyone tell me why this does parse correctly if I use it in the onLoad, but not in the function that I call directly from
4
11997
by: sunil | last post by:
I am creating a XML document which opens fine in IE. Implies MSXML thinks it is a well formed document. But when I try to load this document in VB.net using the following code Dim doc As New XmlDocument doc.Load("C:\Projects\SQLXML\corc.xml") I get the following error: "System.Xml.XmlException: An unexpected end of file parsing CDATA has
6
24352
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an XSLT and replace all occurances of &lt; with < and &gt; with >.
4
11950
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report> </myXml> I there a way that the XSLT transformation can render the content as html rather than text?
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.