简体   繁体   中英

Can I specify an XML schema/xsd when deserializing?

I'm trying to deserialize XML from an external service, so I have no control over the output XML I receive.

The service's XML is a little strange. It doesn't specify a schema, it references itself. For example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE response>
<response>
 // blah blah
</response>

I can use VS's built in tools to create an XSD file for it, but when deserializing, is it possible to specify a local XSD file? Instead of using the non-existent one in the DOCTYPE tag?

You might need to specify to not use an XmlResolver when loading the XML document. See Ignore DOCTYPE .dtd, but .dtd file must still exist

You can easily specify the .xsd file. Use an XmlReaderSettings object when you load the document. Note that if your program is a web service, your .xsd might need to reside under the Windows directory. For a hint at it, including pain on 64 bit Windows, see MSI Installer, 64 bit OS, write to \\windows\\system32\\inetsrv folder

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