[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Parsing XML from a CDATA Structure

Subject: Parsing XML from a CDATA Structure
From: Olson Family <olsonfam@xxxxxxxxxxxxx>
Date: Wed, 03 Aug 2005 20:23:03 -0400
java cdata
Using Saxon 8,  I am attempting to parse an XML string from within a CDATA
Structure.

Using the saxon:parse extension I have been able to do this, except when the
xml string includes the following tag at the beginning of the string.

<?xml version="1.0" encoding="UTF-8"?>

I am getting the following error

  net.sf.saxon.xpath.DynamicError: org.xml.sax.SAXParseException: The
processing instruction
  target matching "[xX][mM][lL]" is not allowed.
Transformation failed: Run-time errors were reported

The sample xsl file will succesfully parse the xml file if I remove the
string from the cdata structure.

I don't control the structure of the XML, so I do not have the ability to
somehow strip out the ?xml string.

Is there any way to have Saxon ignore this string.



===============file.xsl===========================

>     <?xml version="1.0" encoding="ISO-8859-1" ?>
>     <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/">
>     <xsl:output method="text" indent="no"/>
>     <xsl:template match="/">
>                     <xsl:apply-templates
select="busmessage/body/field[@name='^data^']"/>
>     </xsl:template>
>
>             <xsl:template match="busmessage/body/field[@name='^data^']">
>
>                     <ID>
>                             <xsl:variable name="dynamic"
select="saxon:parse(field[@name='body'])"/>
>                             <xsl:value-of
select="$dynamic/usiTradeEvent/tradeId"/>
>                     </ID>
>             </xsl:template>
>     </xsl:stylesheet>

===============file.xml (with <?xml version="1.0" encoding="UTF-8"?>) string
=================

>     <?xml version="1.0"?>
>     <busmessage>
>     <header>
>     <sendSubject>TEST.MESSAGE</sendSubject>
>     <replySubject></replySubject>
>     <sender seq="2687" timeLimit="0.0">AuroraPub</sender>
>     </header>
>     <body>
>     <field name="^pfmt^" busType="16" javaType="java.lang.Short" id="0">
>     10</field>
>     <field name="^ver^" busType="16" javaType="java.lang.Short" id="0">
>     30</field>
>     <field name="^type^" busType="16" javaType="java.lang.Short" id="0">
>     1</field>
>     <field name="^encoding^" busType="16" javaType="java.lang.Short"
id="0">
>     1</field>
>     <field name="^prefixList^" busType="1"
javaType="com.tibco.tibrv.TibrvMsg" id="0">
>     <field name="default" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[/tibco/public/class/DEFI/FI/Upstreaminterfaces/CF]]>
>     </field>
>     </field>
>     <field name="^tracking^" busType="1"
javaType="com.tibco.tibrv.TibrvMsg" id="0">
>     <field name="^id^" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[1LE--A--EixxCk6Q-0q6eX6Bs-ItI]]>
>     </field>
>     <field name="^1^" busType="8" javaType="java.lang.String" id="1">
>
<![CDATA[BW.Aurora-Aurora.Process/DEFI/FI/Upstreaminterfaces/Aurora.process.
Job-18148]]>
>     </field>
>     </field>
>     <field name="^data^" busType="1" javaType="com.tibco.tibrv.TibrvMsg"
id="0">
>     <field name="^class^" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[CFMsg]]>
>     </field>
>     <field name="body" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
>     <usiTradeEvent>
>         <eventType>New</eventType>
>         <tradeType>Buy</tradeType>
>         <tradeScheme>MUSTANG</tradeScheme>
>         <tradeId>RICHO-00123456</tradeId>
>         <tradeVersion>0</tradeVersion>
>         <portfolioId>MPT1</portfolioId>
>         <partyScheme>CIF</partyScheme>
>         <partyType>COUNTERPARTY</partyType>
>         <partyId>MX-5</partyId>
>         <traderScheme>MUSTANG</traderScheme>
>         <traderId>RGrandur</traderId>
>         <marginAmount>0.000000</marginAmount>
>         <marginBpMultiplier>1</marginBpMultiplier>
>         <tradeDate>2005-08-02</tradeDate>
>         <inputTimeStamp>2005-08-02</inputTimeStamp>
>         <comment>TW</comment>
>         <bond>
>             <securityScheme>CUSIP</securityScheme>
>             <securityId>VRR562</securityId>
>             <nominalAmount>38.00</nominalAmount>
>             <priceType>PRICE</priceType>
>             <price>98.9921875000</price>
>             <settlementDate>2005-08-03</settlementDate>
>         </bond>
>     </usiTradeEvent>]]>
>     </field>
>     </field>
>     </body>
>     </busmessage>

================= output ==============================
  net.sf.saxon.xpath.DynamicError: org.xml.sax.SAXParseException: The
processing instruction
  target matching "[xX][mM][lL]" is not allowed.
Transformation failed: Run-time errors were reported

===============file1.xml (without <?xml version="1.0" encoding="UTF-8"?>)
string =================
>     <?xml version="1.0"?>
>     <busmessage>
>     <header>
>     <sendSubject>TEST.MESSAGE</sendSubject>
>     <replySubject></replySubject>
>     <sender seq="2687" timeLimit="0.0">AuroraPub</sender>
>     </header>
>     <body>
>     <field name="^pfmt^" busType="16" javaType="java.lang.Short" id="0">
>     10</field>
>     <field name="^ver^" busType="16" javaType="java.lang.Short" id="0">
>     30</field>
>     <field name="^type^" busType="16" javaType="java.lang.Short" id="0">
>     1</field>
>     <field name="^encoding^" busType="16" javaType="java.lang.Short"
id="0">
>     1</field>
>     <field name="^prefixList^" busType="1"
javaType="com.tibco.tibrv.TibrvMsg" id="0">
>     <field name="default" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[/tibco/public/class/DEFI/FI/Upstreaminterfaces/CF]]>
>     </field>
>     </field>
>     <field name="^tracking^" busType="1"
javaType="com.tibco.tibrv.TibrvMsg" id="0">
>     <field name="^id^" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[1LE--A--EixxCk6Q-0q6eX6Bs-ItI]]>
>     </field>
>     <field name="^1^" busType="8" javaType="java.lang.String" id="1">
>
<![CDATA[BW.Aurora-Aurora.Process/DEFI/FI/Upstreaminterfaces/Aurora.process.
Job-18148]]>
>     </field>
>     </field>
>     <field name="^data^" busType="1" javaType="com.tibco.tibrv.TibrvMsg"
id="0">
>     <field name="^class^" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[CFMsg]]>
>     </field>
>     <field name="body" busType="8" javaType="java.lang.String" id="0">
>     <![CDATA[<usiTradeEvent>
>         <eventType>New</eventType>
>         <tradeType>Buy</tradeType>
>         <tradeScheme>MUSTANG</tradeScheme>
>         <tradeId>RICHO-00123456</tradeId>
>         <tradeVersion>0</tradeVersion>
>         <portfolioId>MPT1</portfolioId>
>         <partyScheme>CIF</partyScheme>
>         <partyType>COUNTERPARTY</partyType>
>         <partyId>MX-5</partyId>
>         <traderScheme>MUSTANG</traderScheme>
>         <traderId>RGrandur</traderId>
>         <marginAmount>0.000000</marginAmount>
>         <marginBpMultiplier>1</marginBpMultiplier>
>         <tradeDate>2005-08-02</tradeDate>
>         <inputTimeStamp>2005-08-02</inputTimeStamp>
>         <comment>TW</comment>
>         <bond>
>             <securityScheme>CUSIP</securityScheme>
>             <securityId>VRR562</securityId>
>             <nominalAmount>38.00</nominalAmount>
>             <priceType>PRICE</priceType>
>             <price>98.9921875000</price>
>             <settlementDate>2005-08-03</settlementDate>
>         </bond>
>     </usiTradeEvent>]]>
>     </field>
>     </field>
>     </body>
>     </busmessage>

================= output ==============================
RICHO-00123456

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.