Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XmlReaderSettings does not resolve an xs:import with http://... location

XmlReaderSettings does not resolve an xs:import with http://... location

Scheduled Pinned Locked Moved XML / XSL
xmlquestiondatabasedebuggingtutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giangilpredo
    wrote on last edited by
    #1

    Hi, I'm trying to validate an Xml document using an XmlReader. Here is my code: private void Validate(TextReader source, string xsd) { XmlReaderSettings settings = new XmlReaderSettings(); XmlUrlResolver resolver = new XmlUrlResolver(); settings.ProhibitDtd = false; resolver.Credentials = CredentialCache.DefaultCredentials; settings.XmlResolver = resolver; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; settings.Schemas.XmlResolver = resolver; settings.Schemas.Add(null, xsd); settings.Schemas.Compile(); \\settings.Schemas.Add(null, http://www.w3.org/2001/xml.xsd); settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += ValidationHandler; XmlReader reader = XmlReader.Create(source, settings); while (reader.Read()) { } } The xsd of the xml document I want to validate contains an xs:import that points to local xsd (the schemaLocation is, as example "./dc.xsd"). This xsd imports serveral other xsd, one of which is the following: When settings.Schemas.Add(null,xsd) is executed, all nested LOCAL xsd are correctly resolved by the XmlUrlResolver I created. If i inspect during debug my XmlReaderSetting instance i can see tha all the required xsd are correctly loaded, EXCEPT http://www.w3.org/2001/03/xml.xsd. Then settings.Schemas.Compile() is executed, an exception is raised telling me that the attribute xml:lang is not defined (it's defined in the missing xsd). This exception is not raised, and validaion is performed correctly, if i manually add the namespace (see the commented line of my code), or if i change the scema location in the xsd file to point to a local copy of xml.xsd (schemaLocation="./xml.xsd"). I would like to know how can I make this work, because i don't want to add manually anything related to this specific scenario (i.e. i would like to reuse the code). In other words, why this remote location is not resolved?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups