471,093 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,093 software developers and data experts.

xmlSchemaSet compile and xs:import error

Hi,

I have following schema saved in new.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema
targetNamespace="http://www.smpte-ra.org/schemas/429.7/2006/CPL"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:cpl="http://www.smpte-ra.org/schemas/429.7/2006/CPL"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
<xs:element name="CompositionPlaylist"
type="cpl:CompositionPlaylistType"/>
<xs:complexType name="CompositionPlaylistType">
<xs:sequence>
<xs:element name="Id" type="cpl:UUID"/>
<xs:element name="AnnotationText" type="cpl:UserText"
minOccurs="0"/>
<xs:element name="Signer" type="ds:KeyInfoType" minOccurs="0"/>
<xs:element ref="ds:Signature" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="UUID">
<xs:restriction base="xs:anyURI">
<xs:pattern
value="urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="UserText">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language" use="optional"
default="en"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

I am using following code to add the schema to schemaset and compile.
Compile generates exception -
http://www.w3.org/2000/09/xmldsig#:KeyInfoType' is not declared.

Any suggestions as to what I may be doing wrong or what I need to do in
addition to this. Actually I need to validate XML against schema and I
am using XMLReaderSettings and was not able to create the xmlreader so
I just added compile statement to see if my SchemaSet.schemas has
everything and looks like the issue is with Schemaset since it is not
compiling also in .Net 2.0 Add does not compile the schema
automatically.

Suggestions will be of great help

Apr 29 '06 #1
3 7375
Missed the lil piece of code

try
{
XmlSchemaSet ss = new XmlSchemaSet();
ss.Add(null, "new.xsd");
ss.Compile();
}
catch(XmlSchemaException e)
{
Console.WriteLine(e);
}

Apr 29 '06 #2
This is because the xml-dsig schema has DTD definition in it and by default
..NET XmlSchemaSet parses the schema with a reader that has ProhibitDtd =
true.
For your case, on XmlSchemaSet.Add(), you will get the following warning:

Exception Severity: Warning
Cannot resolve the 'schemaLocation' attribute.
An Error Occurred at: file:///E:/bugrepro/new1.xsd, (8,2)
Inner exception: System.Xml.XmlException: For security reasons DTD is
prohibited in this XML document. To enable DTD processing
set the ProhibitDtd property on XmlReaderSettings to false and pass the
settings into XmlReader.Create method.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent( )
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Schema.Parser.StartParsing(XmlReader reader, String
targetNamespace)
at System.Xml.Schema.Parser.Parse(XmlReader reader, String
targetNamespace)
at System.Xml.Schema.Preprocessor.LoadExternals(XmlSc hema schema)
System.Xml.Schema.XmlSchemaImport 8 2

In order to be able to parse schemas that have DTDs in them, you need to
create an XmlReader that allows dtds as shown below:
XmlReaderSettings schemaReaderSettings = new XmlReaderSettings();
schemaReaderSettings.ProhibitDtd = false;
XmlReader schemaReader = XmlReader.Create("new.xsd", schemaReaderSettings);
try {
XmlSchemaSet set = new XmlSchemaSet();
set.Add(null, schemaReader);
set.Compile();
}
catch(XmlException e) {
Console.WriteLine(e.Message + " at" + e.LineNumber);
}

Thanks,
Priya

<sa********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi,

I have following schema saved in new.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema
targetNamespace="http://www.smpte-ra.org/schemas/429.7/2006/CPL"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:cpl="http://www.smpte-ra.org/schemas/429.7/2006/CPL"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
<xs:element name="CompositionPlaylist"
type="cpl:CompositionPlaylistType"/>
<xs:complexType name="CompositionPlaylistType">
<xs:sequence>
<xs:element name="Id" type="cpl:UUID"/>
<xs:element name="AnnotationText" type="cpl:UserText"
minOccurs="0"/>
<xs:element name="Signer" type="ds:KeyInfoType" minOccurs="0"/>
<xs:element ref="ds:Signature" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="UUID">
<xs:restriction base="xs:anyURI">
<xs:pattern
value="urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="UserText">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language" use="optional"
default="en"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

I am using following code to add the schema to schemaset and compile.
Compile generates exception -
http://www.w3.org/2000/09/xmldsig#:KeyInfoType' is not declared.

Any suggestions as to what I may be doing wrong or what I need to do in
addition to this. Actually I need to validate XML against schema and I
am using XMLReaderSettings and was not able to create the xmlreader so
I just added compile statement to see if my SchemaSet.schemas has
everything and looks like the issue is with Schemaset since it is not
compiling also in .Net 2.0 Add does not compile the schema
automatically.

Suggestions will be of great help

May 1 '06 #3
It Worked. Thanks.
But the system should be connected to internet else it will not be able
to resolve the imports.
Thanks

Sachin
Priya Lakshminarayanan wrote:
This is because the xml-dsig schema has DTD definition in it and by default
.NET XmlSchemaSet parses the schema with a reader that has ProhibitDtd =
true.
For your case, on XmlSchemaSet.Add(), you will get the following warning:

Exception Severity: Warning
Cannot resolve the 'schemaLocation' attribute.
An Error Occurred at: file:///E:/bugrepro/new1.xsd, (8,2)
Inner exception: System.Xml.XmlException: For security reasons DTD is
prohibited in this XML document. To enable DTD processing
set the ProhibitDtd property on XmlReaderSettings to false and pass the
settings into XmlReader.Create method.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent( )
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Schema.Parser.StartParsing(XmlReader reader, String
targetNamespace)
at System.Xml.Schema.Parser.Parse(XmlReader reader, String
targetNamespace)
at System.Xml.Schema.Preprocessor.LoadExternals(XmlSc hema schema)
System.Xml.Schema.XmlSchemaImport 8 2

In order to be able to parse schemas that have DTDs in them, you need to
create an XmlReader that allows dtds as shown below:
XmlReaderSettings schemaReaderSettings = new XmlReaderSettings();
schemaReaderSettings.ProhibitDtd = false;
XmlReader schemaReader = XmlReader.Create("new.xsd", schemaReaderSettings);
try {
XmlSchemaSet set = new XmlSchemaSet();
set.Add(null, schemaReader);
set.Compile();
}
catch(XmlException e) {
Console.WriteLine(e.Message + " at" + e.LineNumber);
}

Thanks,
Priya

<sa********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi,

I have following schema saved in new.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema
targetNamespace="http://www.smpte-ra.org/schemas/429.7/2006/CPL"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:cpl="http://www.smpte-ra.org/schemas/429.7/2006/CPL"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
<xs:element name="CompositionPlaylist"
type="cpl:CompositionPlaylistType"/>
<xs:complexType name="CompositionPlaylistType">
<xs:sequence>
<xs:element name="Id" type="cpl:UUID"/>
<xs:element name="AnnotationText" type="cpl:UserText"
minOccurs="0"/>
<xs:element name="Signer" type="ds:KeyInfoType" minOccurs="0"/>
<xs:element ref="ds:Signature" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="UUID">
<xs:restriction base="xs:anyURI">
<xs:pattern
value="urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="UserText">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language" use="optional"
default="en"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

I am using following code to add the schema to schemaset and compile.
Compile generates exception -
http://www.w3.org/2000/09/xmldsig#:KeyInfoType' is not declared.

Any suggestions as to what I may be doing wrong or what I need to do in
addition to this. Actually I need to validate XML against schema and I
am using XMLReaderSettings and was not able to create the xmlreader so
I just added compile statement to see if my SchemaSet.schemas has
everything and looks like the issue is with Schemaset since it is not
compiling also in .Net 2.0 Add does not compile the schema
automatically.

Suggestions will be of great help


May 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by PipedreamerGrey | last post: by
1 post views Thread by GujuBoy | last post: by
1 post views Thread by Ed Bacon | last post: by
reply views Thread by Rupa | last post: by
5 posts views Thread by Brice Prunier | last post: by
3 posts views Thread by Nathan Alden | last post: by
3 posts views Thread by Neter Smith | last post: by
2 posts views Thread by randar | last post: by
1 post views Thread by Julia | last post: by

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.