Using unparsed entities in schemas
-
Greeting! As declared in w3.org there is predefined derived type in XSD schemas - the ENTITY. This type is used for attributes, which means are unparsed entities from DTD. Using of the ENTITY as attribute type in schema is not problem (no errors for the schema self-validation) but: 1. XML file didn't pass the schema validation - the XML file didn't find unparsed entities declared in the schema DTD (that's right - it is the schema DTD only) and from other hand the XML file DTD eliminates schema using (that's right too - the DTD is closed model). How to use the ENTITY type? 2. In XSD schemas there is predefined base type - NOTATION. The NOTATION takes values from the schema set of <notation> elements. In other words this replaces using of DTD NOTATION as attribute type. May be it is for the ENTITY type too?
-
Greeting! As declared in w3.org there is predefined derived type in XSD schemas - the ENTITY. This type is used for attributes, which means are unparsed entities from DTD. Using of the ENTITY as attribute type in schema is not problem (no errors for the schema self-validation) but: 1. XML file didn't pass the schema validation - the XML file didn't find unparsed entities declared in the schema DTD (that's right - it is the schema DTD only) and from other hand the XML file DTD eliminates schema using (that's right too - the DTD is closed model). How to use the ENTITY type? 2. In XSD schemas there is predefined base type - NOTATION. The NOTATION takes values from the schema set of <notation> elements. In other words this replaces using of DTD NOTATION as attribute type. May be it is for the ENTITY type too?
You can't declare entities in XML Schemas. You can declare them in XML documents that are instances of the schema.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p MVP for 2010 - who'd'a thunk it!
-
You can't declare entities in XML Schemas. You can declare them in XML documents that are instances of the schema.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p MVP for 2010 - who'd'a thunk it!
-
No, IMHO it is impossible to declare entities in XML document if the document has schema because entities are declared in DTD and using of the DTD excludes using of the schema (DTD is closed model).
-
Sorry sir, can You show how You succeed? I can't validate this example. I have used Microsoft XML paser (DOM). There is error - Element "purchaseOrder" is used but not defined in DTD and schema. But there is the validation when I am commenting DTD in the XML file (and deleting symbol "&" for conversion entity to string literal). My JScript code fragment follows. Tell me please, where I have mistaken? var xmldoc = WScript.CreateObject("MsXml2.DomDocument.5.0"); xmldoc.preserveWhiteSpace = false; xmldoc.async = false; xmldoc.validateOnParse = false; xmldoc.load("a.xml"); printResult(xmldoc.parseError); var schema = WScript.CreateObject("Msxml2.XMLSchemaCache.5.0"); schema.add("http://www.example.com/PO1", "a.xsd"); xmldoc.schemas = schema; printResult(xmldoc.validate());
-
Sorry sir, can You show how You succeed? I can't validate this example. I have used Microsoft XML paser (DOM). There is error - Element "purchaseOrder" is used but not defined in DTD and schema. But there is the validation when I am commenting DTD in the XML file (and deleting symbol "&" for conversion entity to string literal). My JScript code fragment follows. Tell me please, where I have mistaken? var xmldoc = WScript.CreateObject("MsXml2.DomDocument.5.0"); xmldoc.preserveWhiteSpace = false; xmldoc.async = false; xmldoc.validateOnParse = false; xmldoc.load("a.xml"); printResult(xmldoc.parseError); var schema = WScript.CreateObject("Msxml2.XMLSchemaCache.5.0"); schema.add("http://www.example.com/PO1", "a.xsd"); xmldoc.schemas = schema; printResult(xmldoc.validate());
I used the .NET XML parser. Here's my little C# program:
using System;
using System.Xml;
using System.Xml.Schema;
namespace a
{
class Program
{
static public void vvv(Object sender, ValidationEventArgs e)
{
Console.WriteLine(e.Message);
throw new XmlSchemaValidationException();
}static void Main(string\[\] args) { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.PreserveWhitespace = false; xmldoc.Load("Changes.xml"); Console.WriteLine(xmldoc.DocumentElement.Name); Console.WriteLine("The document has {0} entities", xmldoc.DocumentType.Entities.Count); XmlSchemaSet schema = new XmlSchemaSet(); schema.Add("", "change-history.xsd"); xmldoc.Schemas = schema; xmldoc.Validate(vvv); Console.WriteLine("Document validated!"); } catch (XmlSchemaValidationException) { Console.WriteLine("Document didn't validate!"); } }
}
}Here's my schema (called 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:documentationComment 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:comp -
I used the .NET XML parser. Here's my little C# program:
using System;
using System.Xml;
using System.Xml.Schema;
namespace a
{
class Program
{
static public void vvv(Object sender, ValidationEventArgs e)
{
Console.WriteLine(e.Message);
throw new XmlSchemaValidationException();
}static void Main(string\[\] args) { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.PreserveWhitespace = false; xmldoc.Load("Changes.xml"); Console.WriteLine(xmldoc.DocumentElement.Name); Console.WriteLine("The document has {0} entities", xmldoc.DocumentType.Entities.Count); XmlSchemaSet schema = new XmlSchemaSet(); schema.Add("", "change-history.xsd"); xmldoc.Schemas = schema; xmldoc.Validate(vvv); Console.WriteLine("Document validated!"); } catch (XmlSchemaValidationException) { Console.WriteLine("Document didn't validate!"); } }
}
}Here's my schema (called 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:documentationComment 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:comp -
Trez bien! Thank You very much! Your code is working without errors, validation is passed. But Your code converted to JScript is working with the same errors. Hence there are errors in the Ms COM implementation of Xml parser.
It does sound like the MS XML parser isn't complete to the standard :-( You would have thought they'd have used the same one for both, wouldn't you :-(
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p MVP for 2010 - who'd'a thunk it!
-
I used the .NET XML parser. Here's my little C# program:
using System;
using System.Xml;
using System.Xml.Schema;
namespace a
{
class Program
{
static public void vvv(Object sender, ValidationEventArgs e)
{
Console.WriteLine(e.Message);
throw new XmlSchemaValidationException();
}static void Main(string\[\] args) { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.PreserveWhitespace = false; xmldoc.Load("Changes.xml"); Console.WriteLine(xmldoc.DocumentElement.Name); Console.WriteLine("The document has {0} entities", xmldoc.DocumentType.Entities.Count); XmlSchemaSet schema = new XmlSchemaSet(); schema.Add("", "change-history.xsd"); xmldoc.Schemas = schema; xmldoc.Validate(vvv); Console.WriteLine("Document validated!"); } catch (XmlSchemaValidationException) { Console.WriteLine("Document didn't validate!"); } }
}
}Here's my schema (called 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:documentationComment 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:compHi! 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 "é"> <!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>é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:documentationComment describing your root element</xs:documentation> </xs:annotation> xs:complexType xs:sequence <xs:element name="items"> xs:complexType