简体   繁体   中英

XSD file path reference

I have written a code where it validates and xml file against xml schema file. During development and testing my xsd file was located and referenced from as C:\\xschema.xsd. This is a exe app , I am not sure how I can includee this file in my visual studio project and reference insde of code. Also it will be included as part of deployment files.

Dim XsdFile as String = "c:\xschema.xsd"
Dim Settings As XmlReaderSettings = New XmlReaderSettings()
Settings.Schemas.Add("", XsdFile)

First add the file to your project using "Add" menu Then change the property "Copy to Output Directory" to "Copy if newer" - this will copy the file to the output directory during build time

and then you can access the file like this:

Dim XsdFile as String = "xschema.xsd"

You can either 1) put a schema hint in your XML files using the xsi:noNamespaceLocation hint and set

Settings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.ProcessSchemaLocation 

2) Have your deployment store the installation path in the Registry for example and construct the path to the schema file during run-time.

3) Put the schema file in your project as "Embedded Resource" and read the schema using

System.Xml.Schema.XmlSchema.Read(stream, validationHandler)

and then add it to the Settings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM