Derick Bailey
Derick Bailey

Reputation: 72868

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?

Upvotes: 2

Views: 2500

Answers (3)

Xavier Decoster
Xavier Decoster

Reputation: 14810

Notice that if you take the xsd from the source control folder in Codeplex, you'll have to replace any occurrence of the string "{0}" with "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" in order for the xsd to work correctly when applied to your nuspec file.

Don't forget to put your nuspec file's root element inside the http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd namespace:

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">

Upvotes: 0

SerialSeb
SerialSeb

Reputation: 6766

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.

Upvotes: 2

ferventcoder
ferventcoder

Reputation: 12561

I think you need this: <package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

Notice the requied fields from NuGet.codeplex.com

Below is an example of a package I have working:

<?xml version="1.0"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <metadata>
    <id>SidePOP</id>
    <version>0.0.1.44</version>
    <authors>Rob Reynolds, Tim Hibbard</authors>
    <owners>Rob Reynolds</owners>
    <summary>SidePOP gives your app the ability to receive email</summary>
    <description>SidePOP allows your application the ability to receive email</description>
    <projectUrl>http://sidepop.googlecode.com</projectUrl>
    <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <tags>email</tags>
    <!--<iconUrl>32x32.png</iconUrl>-->
    <dependencies>
      <dependency id="log4net" version="1.2.10" />
    </dependencies>
  </metadata>
</package>

Upvotes: 1

Related Questions