XML : Why XDocument.Validate return true for xml of another namespace

I have a very simple xsd file:

  <?xml version="1.0" encoding="UTF-8" standalone="no"?>  <xs:schema xmlns="http://schemas.openxmlformats.org/package/2006/content-types"    xmlns:xs="http://www.w3.org/2001/XMLSchema">  </xs:schema>    

(Was written for validating docx's [Content_Type].xml files).

And a simple program for validating xml against xsd:

  XmlSchemaSet schemas = new XmlSchemaSet();  schemas.Add("", "opc-contentTypes.xsd");  XDocument doc = XDocument.Load(xml_file_path);  string msg = "";  doc.Validate(schemas, (o, e) => { msg += e.Message + Environment.NewLine; });  Console.WriteLine(msg == "" ? "Document is valid" : "Document invalid");    

This program knows to return invalid for the next xml:

  <?xml version="1.0" encoding="UTF-8"?>  <shiporder orderid="889923"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="shiporder.xsd">    <orderperson>John Smith</orderperson>    <shiptos>      <name>Ola Nordmann</name>      <address>Langgt 23</address>      <city>4000 Stavanger</city>      <country>Norway</country>    </shiptos>  </shiporder>    

But, for some reason it returns vaild for another docx's xml file which should be invalid (because it has another namesapace...):

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">      <Template>Normal.dotm</Template>      <TotalTime>1</TotalTime>      <Pages>1</Pages>      <Words>1</Words>      <Characters>11</Characters>      <Application>Microsoft Office Word</Application>      <DocSecurity>0</DocSecurity>      <Lines>1</Lines>      <Paragraphs>1</Paragraphs>      <ScaleCrop>false</ScaleCrop>      <Company/>      <LinksUpToDate>false</LinksUpToDate>      <CharactersWithSpaces>11</CharactersWithSpaces>      <SharedDoc>false</SharedDoc>      <HyperlinksChanged>false</HyperlinksChanged>      <AppVersion>15.0000</AppVersion>  </Properties>    

(This is the content of a docx's app.xml file)

Why does this specific file detected as a valid file, while it has other namesapce?

Thanks!

No comments:

Post a Comment