Solved

xslCompiledTransform undefined entity error on euro symbol

Posted on 2013-01-20
5
1,087 Views
Last Modified: 2013-01-20
Dear all,

First of all I'm new to XSL transformations and XML processing!

I am dealing with a third party xml file which looks like (fragment):

<?xml version="1.0"?>
<!DOCTYPE mail SYSTEM "http://www.mijnwinkel.nl/DTD/order_v2.dtd"
><mail version="2.0" >
<set id="session" sequence="1" version="1.1" ><property id="calc_vat" label="" sequence="0" resource_label="" show_type="" name="" >1</property>
<property id="emailvendor" label="" sequence="" resource_label="" show_type="" name="" >mvette@avn-ned.com;info@erma-design.nl</property>
<property id="emailvendor_reply" label="" sequence="" resource_label="" show_type="" name="" >mvette@avn-ned.com</property>
<property id="exentedVAT" label="" sequence="0" resource_label="" show_type="" name="" >1</property>
<property id="order_shopnumber" label="" sequence="" resource_label="" show_type="" name="" >2380602</property>
<property id="ordernumber" label="" sequence="" resource_label="" show_type="" name="" >2380600_00020</property>
<property id="shopnumber" label="" sequence="" resource_label="" show_type="" name="" >2380602</property>
<set id="actions" sequence="1" version="" ><property id="active" label="" sequence="0" resource_label="" show_type="" name="" >true</property>
<property id="total" label="" sequence="0" resource_label="" show_type="" name="" >0</property>
</set>


The referenced DTD (http://www.mijnwinkel.nl/DTD/order_v2.dtd) look like this:

<!ENTITY nbsp " ">
<!ENTITY euro "&#8364;">
<!ELEMENT set (property | set)*>
<!ATTLIST set id CDATA #IMPLIED>
<!ATTLIST set sequence CDATA #IMPLIED>
<!ATTLIST set version CDATA #IMPLIED>
<!ELEMENT property (#PCDATA)>
<!ATTLIST property id CDATA #IMPLIED>
<!ATTLIST property label CDATA #IMPLIED>
<!ATTLIST property sequence CDATA #IMPLIED>
<!ATTLIST property resource_label CDATA #IMPLIED>
<!ATTLIST property show_type CDATA #IMPLIED>
<!ATTLIST property name CDATA #IMPLIED>
<!ELEMENT mail (set)*>
<!ATTLIST mail version CDATA #IMPLIED>


I have made a xsl script to get some clear xml instead of the recursive 'set' and property elements:

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

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8"
        indent="yes" />
   
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="property">
        <xsl:element name="{@id}" namespace="http://tempuri.org/OrderinfoDataSet.xsd">
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>
    <xsl:template match="mail">
        <xsl:element name="OrderinfoDataSet" namespace="http://tempuri.org/OrderinfoDataSet.xsd">
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>
   
    <xsl:template match="set">
        <xsl:element name="{@id}" namespace="http://tempuri.org/OrderinfoDataSet.xsd">
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>


Now when applying this in Oxygen xml developer I get (fragment):

<?xml version="1.0" encoding="UTF-8"?>
-<OrderinfoDataSet xmlns="http://tempuri.org/OrderinfoDataSet.xsd">
<session>
       <calc_vat>1</calc_vat>
        .....
       <amount-inc-vat>€ 126,35</amount-inc-vat>


With the € coming from "&euro; 126,35"  in the source xml....

Now in C# I'm trying to call this xsl to get a nice converted xml file which I can load against a dataset.
Problem is that the code is going down on the euro-sign:
Reference to undeclared entity 'euro'. Line 13, position 135.

code fragment:

var resolver = new XmlUrlResolver
                        {
                            Credentials = System.Net.CredentialCache.DefaultCredentials
                        };
                    // xsl template for transformation            
                    var xslCompiledTransform = new XslCompiledTransform();
                    xslCompiledTransform.Load("import.xsl", XsltSettings.Default, resolver);
                    // xml content reader            
                    var settings = new XmlReaderSettings {XmlResolver = null};
                    settings.DtdProcessing = System.Xml.DtdProcessing.Ignore;

                    var xmlSettings = new XmlWriterSettings();
                    //&euro en de lege namespaces in customer

                    var reader = XmlReader.Create(file, settings);
                    using (var w = XmlWriter.Create(temppath + @"\temp.xml", xmlSettings))
                    {
                        xslCompiledTransform.Transform(reader, w); //ERROR
                    }

My question is:
Can I alter my XSL (entity declarations perhaps) in order to get the transformation done in C# without the error?
Or should I remove all the euro symbols within the code (and how would that look)?

I really don't care about the Euro symbols , as I don't need 'm for further processing.
So if the XSL could be altered in a way that the Euro signs would disappear , that would be fine!

Thank you very much in advance!

Kind regards,
Jahwik
0
Comment
Question by:Jahwik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 38799188
The XML, DTD and XSLT are all correct.
But you need to makes ure that the DTD is not ignored when running the XSLT.
Without the DTD, the XML is not wellformed due to the Euro entity

I think you need to drop this line and it will be OK
settings.DtdProcessing = System.Xml.DtdProcessing.Ignore;
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 38799190
Try this
settings.DtdProcessing = System.Xml.DtdProcessing.Parse;

removing it will set it to the default "Prohibit", but that is not what you want
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 38799196
setting the entity declaration on the XSLT would only be usefull if you would want to use th &euro; in the XSLT itself.
Note that the XSLT process wil resolve the entity whilst parsing the XML against the DTD, and from the start of the actual XSLT process up to the transformation result this Euro will be handled as a UTF-8 char
0
 

Author Comment

by:Jahwik
ID: 38799243
Gertone,
unfortunately, changing the DtdProcessing property to 'Parse' didn't work. I tried it before.

But, you got me thinking when looking at the previous lines of code:
var settings = new XmlReaderSettings { XmlResolver = null}; (??)

If I change this to:
 var settings = new XmlReaderSettings { XmlResolver = resolver };
(with resolver is of type  XmlUrlResolver , declares earlier), then the transformation goes well.....

So thanks a lot Gertone, I can carry on with the processing ;)

Jahwik
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 38799275
sounds good,
welcome
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question