2

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?

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219

3 Answers3

2

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.

SerialSeb
  • 6,701
  • 24
  • 28
  • FWIW we've fixed most of our tools to always generate property xml. We made some mistakes pre 1.0 and ended up supporting older xml versions. – davidfowl Mar 03 '11 at 15:40
  • For the record that URL is now useless - instead you get: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." – SlySven Oct 18 '20 at 18:15
1

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>
ferventcoder
  • 11,952
  • 3
  • 57
  • 90
  • didn't fix it. i added both the xmlns:xsd and xmlns:xsi, and i also added the xmlns to the metadata element and am still getting the same error – Derick Bailey Feb 25 '11 at 17:23
  • Note that there is no consistency whatsoever in the wild as to when the namespace is supposed to be there or not. – SerialSeb Feb 25 '11 at 18:55
  • We've fixed this in the next version and we're fixing our docs to show the correct way to declare the schema. – davidfowl Mar 20 '11 at 18:13
0

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">
Xavier Decoster
  • 14,580
  • 5
  • 35
  • 46