Click here to Skip to main content
15,896,111 members
Home / Discussions / XML / XSL
   

XML / XSL

 
AnswerRe: Using unparsed entities in schemas Pin
Stuart Dootson13-Jan-10 0:26
professionalStuart Dootson13-Jan-10 0:26 
GeneralRe: Using unparsed entities in schemas Pin
rusgregor13-Jan-10 4:18
rusgregor13-Jan-10 4:18 
GeneralRe: Using unparsed entities in schemas Pin
Stuart Dootson13-Jan-10 4:25
professionalStuart Dootson13-Jan-10 4:25 
GeneralRe: Using unparsed entities in schemas Pin
rusgregor14-Jan-10 3:23
rusgregor14-Jan-10 3:23 
GeneralRe: Using unparsed entities in schemas Pin
Stuart Dootson14-Jan-10 4:44
professionalStuart Dootson14-Jan-10 4:44 
GeneralRe: Using unparsed entities in schemas Pin
rusgregor14-Jan-10 21:24
rusgregor14-Jan-10 21:24 
GeneralRe: Using unparsed entities in schemas Pin
Stuart Dootson14-Jan-10 22:00
professionalStuart Dootson14-Jan-10 22:00 
GeneralRe: Using unparsed entities in schemas Pin
rusgregor18-Jan-10 2:09
rusgregor18-Jan-10 2:09 
Hi! Unfortunly, our long and winding road is continuing. The Ms .NET XML parser is not finished too. After passing Your successfull example, I tried to pass example of using unparsed entity. I added some entity and it notation in the DTD and some attribute definition of the ENTITY type in the schema. After I added this attribute with the unparsed entity value and executed Your program. The test was ok. But after I assigned to the attribute improper value (not unparsed entity) and test was once again ok! After my tests I have a mind that the parser checks attributes of the ENTITY type as of the the NCName type (the direct ancestor of the ENTITY type). The XML file and schema is here:

Changes.xml

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE change-history [
<!ENTITY eacute "&#xE9;">
<!NOTATION MyNotation SYSTEM "My Notation">
<!ENTITY MyEntity SYSTEM "My Entity" NDATA MyNotation>
]>
<change-history product="Sample" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="change-history.xsd">
   <items>
         <item name="Sample.exe">
            <version number="2.21.0" entity = "MyEntity">
                  <change reason="issue 11">Added license to executable.</change>
                  <change>&eacute;Fixed bug in executable.</change>
            </version>
         </item>
   </items>
</change-history>

change-history.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
   <xs:element name="change-history">
      <xs:annotation>
         <xs:documentation>Comment describing your root element</xs:documentation>
      </xs:annotation>
      <xs:complexType>
         <xs:sequence>
            <xs:element name="items">
               <xs:complexType>
                  <xs:sequence maxOccurs="unbounded">
                     <xs:element name="item">
                        <xs:complexType>
                           <xs:sequence maxOccurs="unbounded">
                              <xs:element name="version">
                                 <xs:complexType>
                                    <xs:sequence maxOccurs="unbounded">
                                       <xs:element name="change">
                                          <xs:complexType>
                                             <xs:simpleContent>
                                                <xs:extension base="xs:string">
                                                   <xs:attribute name="reason" type="xs:string" use="optional"/>
                                                </xs:extension>
                                             </xs:simpleContent>
                                          </xs:complexType>
                                       </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="number" type="xs:string" use="required"/>
                                    <xs:attribute name="entity" type="xs:ENTITY" use="required"/>
                                 </xs:complexType>
                              </xs:element>
                           </xs:sequence>
                           <xs:attribute name="name" type="xs:string" use="required"/>
                        </xs:complexType>
                     </xs:element>
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
         <xs:attribute name="product" type="xs:string" use="required"/>
      </xs:complexType>
   </xs:element>
</xs:schema>

From other hand, the DTD validation is strict - only unparsed entity can by the value of the ENTITY attribute. For the proving the XML file and C# program is here:

example.xml

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE change-history [
<!ENTITY eacute "&#xE9;">
<!NOTATION MyNotation SYSTEM "My Notation">
<!ENTITY MyEntity SYSTEM "My Entity" NDATA MyNotation>
<!ELEMENT change-history EMPTY>
<!ATTLIST change-history entity ENTITY #REQUIRED>
]>

<change-history entity = "MyEntity"/>

the program

using System;
using System.Xml;
using System.Xml.Schema;
namespace a
{
   class Program
   {
         static void Main(string[] args)
         {
            try
            {
                  XmlDocument xmldoc = new XmlDocument();
                  xmldoc.PreserveWhitespace = false;
                  XmlValidatingReader reader =
                  new XmlValidatingReader(new XmlTextReader("Example.xml"));
                  reader.ValidationEventHandler +=
                  new ValidationEventHandler(vh);
                  reader.ValidationType = ValidationType.DTD;
                  xmldoc.Load(reader);
                  Console.WriteLine(xmldoc.DocumentElement.Name);
                  Console.WriteLine("The document has {0} entities", xmldoc.DocumentType.Entities.Count);
                  Console.WriteLine("Document validated!");
            }
            catch (XmlSchemaValidationException)
            {
                  Console.WriteLine("Document didn't validate!");
            }
         }

         static private void vh(Object sender, ValidationEventArgs args)
         {
         Console.WriteLine(args.Message);
         throw args.Exception;
         }
   }
}

Of course, we can use double validation - at begining to use a schema validation and after success to use own validation routine checking the unparsed entities. But IMHO it's not fine decision.
QuestionXQuery Pin
Lutosław9-Jan-10 23:40
Lutosław9-Jan-10 23:40 
AnswerRe: XQuery Pin
Stuart Dootson12-Jan-10 3:07
professionalStuart Dootson12-Jan-10 3:07 
GeneralRe: XQuery Pin
Lutosław12-Jan-10 4:02
Lutosław12-Jan-10 4:02 
AnswerRe: XQuery Pin
Lutosław12-Jan-10 4:01
Lutosław12-Jan-10 4:01 
QuestionXML opening with IE Pin
Aljaz1117-Jan-10 4:07
Aljaz1117-Jan-10 4:07 
AnswerRe: XML opening with IE Pin
vivasaayi7-Jan-10 18:20
vivasaayi7-Jan-10 18:20 
QuestionXML With C# Pin
jojoba20105-Jan-10 22:23
jojoba20105-Jan-10 22:23 
AnswerRe: XML With C# Pin
vivasaayi7-Jan-10 18:45
vivasaayi7-Jan-10 18:45 
QuestionHow can I generate multiple classes from xsd’s with common includes? Pin
sri_00994-Jan-10 2:46
sri_00994-Jan-10 2:46 
QuestionGenerate Dynamic controls using XSLT Pin
getaccessyr3-Jan-10 22:33
getaccessyr3-Jan-10 22:33 
AnswerRe: Generate Dynamic controls using XSLT Pin
Not Active4-Jan-10 1:19
mentorNot Active4-Jan-10 1:19 
QuestionGetting zero elements with xmldocument.selectnodes Pin
Haim Nachum2-Jan-10 10:55
Haim Nachum2-Jan-10 10:55 
AnswerRe: Getting zero elements with xmldocument.selectnodes Pin
Dexter Legaspi20-Jan-10 16:13
Dexter Legaspi20-Jan-10 16:13 
QuestionHelp with xml within dll file Pin
LeeWhit28-Dec-09 19:36
LeeWhit28-Dec-09 19:36 
Question2 xml used from the same hmtl page Pin
Russell'20-Dec-09 1:04
Russell'20-Dec-09 1:04 
QuestionXSL +query string value Pin
sangeethanarayan18-Dec-09 2:26
sangeethanarayan18-Dec-09 2:26 
AnswerRe: XSL +query string value Pin
Brij21-Dec-09 7:38
mentorBrij21-Dec-09 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.