Schema validation with namespaces

970 views
Skip to first unread message

Les

unread,
Feb 6, 2010, 5:30:55 PM2/6/10
to nokogiri-talk
Banging my head against the wall on this one. Help would be much
appreciated.

I'm working with open xml documents, and I'm trying to validate an xml
doc against the published standards (http://openxmldeveloper.org/
archive/2006/09/12/641.aspx), I'm using the file called dml-chart.xsd.
It imports namespaces from several of the other xsd files in the
collection.

Now I'm pretty confident that these are well-formed XSD files, but
when I do:

xsd_file = File.join(xsd_file_path,"dml-chart.xsd")
xsd = Nokogiri::XML::Schema(File.read(xsd_file))

I get the error message:
Nokogiri::XML::SyntaxError: element decl. '{http://
schemas.openxmlformats.org/drawingml/2006/chart}txPr', attribute
'type': The QName value '{http://schemas.openxmlformats.org/drawingml/
2006/main}CT_TextBody' does not resolve to a(n) type definition.

So the parser doesn't seem to understand the namespaces in the
document. Does anyone have any ideas how to load up a schema which has
namespaces and attributes defined in other files?

thanks in advance for any clues that anyone can provide

Les

Aaron Patterson

unread,
Feb 6, 2010, 6:55:31 PM2/6/10
to nokogi...@googlegroups.com
On Sat, Feb 6, 2010 at 2:30 PM, Les <codeh...@comcast.net> wrote:
> Banging my head against the wall on this one. Help would be much
> appreciated.
>
> I'm working with open xml documents, and I'm trying to validate an xml
> doc against the published standards (http://openxmldeveloper.org/
> archive/2006/09/12/641.aspx), I'm using the file called dml-chart.xsd.
> It imports namespaces from several of the other xsd files in the
> collection.
>
> Now I'm pretty confident that these are well-formed XSD files, but
> when I do:
>
> xsd_file = File.join(xsd_file_path,"dml-chart.xsd")
> xsd = Nokogiri::XML::Schema(File.read(xsd_file))

Try loading the schema like this:

xsd = Nokogiri::XML::Schema(File.open(xsd_file))

When you just read from memory, nokogiri doesn't know the source of
the xsd file. If you pass it an open file handle, it can figure it
out.

If that doesn't work, please send in some code that I can try. Then
we can fix the problem for sure. :-)

--
Aaron Patterson
http://tenderlovemaking.com/

Les

unread,
Feb 7, 2010, 1:36:17 PM2/7/10
to nokogiri-talk
Thanks, Aaron, that looked like a good suggestion, but I'm getting the
same error when I pass a file handle.

I'm not sure how to upload code for you to look at. The dml-chart.xsd
file I'm loading is too large to include in a post, and because it
refers to namespaces defined in several other files, it takes a
collection of files just to define the schema. The collection is at
the link in the original post... sorry to point you to that but I'm
not sure how else to show you the information.

Many thanks, Aaron, for your interest and quick response, and hopeful
that you can provide insight. Because of the subject (open xml
document schema files), I'm sure the solution will be of interest to
others in the future.

Les


On Feb 6, 3:55 pm, Aaron Patterson <aaron.patter...@gmail.com> wrote:

Aaron Patterson

unread,
Feb 7, 2010, 2:49:53 PM2/7/10
to nokogi...@googlegroups.com
On Sun, Feb 7, 2010 at 10:36 AM, Les <codeh...@comcast.net> wrote:
> Thanks, Aaron, that looked like a good suggestion, but I'm getting the
> same error when I pass a file handle.

Are you sure that dml-chart.xsd is the correct xsd file to load? Even
xmllint throws processing errors when I tell it to use that xsd file.
There is a dml-baseStylesheet.xsd that seems to load ok. Maybe that
one includes the chart styles?

Also, if you're sure dml-chart.xsd is the correct file to use, could
you send me links for where you got that info? It may give me clues
as to how to get this to work.

> I'm not sure how to upload code for you to look at. The dml-chart.xsd
> file I'm loading is too large to include in a post, and because it
> refers to namespaces defined in several other files, it takes a
> collection of files just to define the schema. The collection is at
> the link in the original post... sorry to point you to that but I'm
> not sure how else to show you the information.
>
> Many thanks, Aaron, for your interest and quick response, and hopeful
> that you can provide insight. Because of the subject (open xml
> document schema files), I'm sure the solution will be of interest to
> others in the future.

No problem. We're here to help. :-)

Les

unread,
Feb 8, 2010, 4:06:04 PM2/8/10
to nokogiri-talk
Well, no I'm not totally sure it's the right file to load. But it is
not included in any of the other files in the collection, so I'm
inferring that it's a "top-level" file, if that makes sense (does
it?).

If dml-chart.xsd is not included-in or referenced-by any of the other
files, and only includes or references other xsd files in the
collection, shouldn't it properly parse as a schema if it's well-
formed?

What I can' t understand is that it imports namespaces from dml-
text.xsd, and explicitly specifies that schemaLocation, but
Nokogiri::XML::Schema(file_handle_of_dml-chart.xsd) throws an error
that suggests it's not able to resolve the attribute
type="a:CT_TextBody" on the element with name="txPr" (line 387) even
though this is not the first such attribute in the a: namespace,
defined in dml-text.xsd, that it had encountered (e.g. line 386). It
presumably WAS able to resolve the qname of the attribute on line 386.

many thanks for your continuing help and interest

Les


On Feb 7, 11:49 am, Aaron Patterson <aaron.patter...@gmail.com> wrote:

Reply all
Reply to author
Forward
Message has been deleted
0 new messages