Search code examples
xmlvalidationschemanugetnuspec

validating .nuspec file with nuspec.xsd fails on 'package'


I'm trying to validate the following xml, which is inside of a .nuspec file:

<?xml version='1.0'?>
<package>
  <metadata>
    <id>nuspec_test</id>
    <version>1.2.3</version>
    <authors>Author Name</authors>
    <description>test_xml_document</description>
  </metadata>
</package>

For the validation, I'm using the nuspec.xsd file found here: http://nuget.codeplex.com/SourceControl/changeset/view/0881f2d55e70#src%2fCore%2fAuthoring%2fnuspec.xsd

I've run the validation using .Net's System.Xml, and using Ruby's Nokogiri. Both of these show a failure doing the validation, saying the following:

From Nokogiri: Element 'package': No matching global declaration available for the validation root.

From System.XML: Data at the root level is invalid. Line 1, position 1.

What's wrong with this xml, or the schema, that would cause the validation errors?


Solution

  • The package element ought to be in the http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd namespace if you want that xsd to validate.

    Note that the majority of examples out there do not have the xml namespace, so only use it for your own use.