Problems with XPath expressions when C # operations use XSD XML files

Source: Internet
Author: User
Tags xpath

XPath can find the node but associate the. xsd file (schema specification) with the XML file when the original operation does not use an XSD XML file.

There was an error, and the node was not found according to XPath.

Plugin.xsd file when the problem occurs

<?xml version= "1.0" encoding= "Utf-8"?> <xs:schema id= "Plugin" targetnamespace= "Http://tempuri.org/Plugin" elementformdefault= "qualified" xmlns= "Http://tempuri.org/Plugin" xmlns:mstns= "Http://tempuri.org/Plugin" Xmlns:xs = "Http://www.w3.org/2001/XMLSchema" > <xs:element name= "Plugin" > <xs:complexType> <xs:sequence > <xs:element name= "name" type= "xs:string"/> <xs:element name= "Author" type= "xs:string"/> <xs: Element name= "Version" type= "xs:string"/> <xs:element name= "Description" type= "xs:string"/> </xs: sequence> <xs:complexType> <xs:element> </xs:schema>

An XML file when a problem occurs

<?xml version= "1.0" encoding= "Utf-8"?> <plugin xmlns= "Http://tempuri.org/Plugin" xmlns:xsi= "http://" Www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" Http://tempuri.org/Plugin plugin.xsd "> <Name> name </Name> <Author> author </Author> <Version> version </Version> <Description> description </ Description> </Plugin>

PLUGIN.DTD file with problem resolved

<?xml version= "1.0" encoding= "Utf-8"?> <xs:schema id= "Plugin" elementformdefault= "qualified" xmlns:xs= "http ://www.w3.org/2001/XMLSchema "> <xs:element name=" Plugin "> <xs:complexType> <xs:sequence> < Xs:element name= "name" type= "xs:string"/> <xs:element name= "Author" type= "xs:string"/> <xs:element name= " Version "type=" xs:string "/> <xs:element name=" Description "type=" xs:string "/> </xs:sequence> <xs: Complextype> <xs:element> </xs:schema>

Problem-resolved XML file

<?xml version= "1.0" encoding= "Utf-8"?> <plugin xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: nonamespaceschemalocation= "plugin.xsd" >//XSD and XML in the same directory <Name> name </Name> <Author> author </author > <Version> version </Version> <Description> description </Description> </Plugin>

To specify a location for an XML schema that does not have a target namespace, use the noNamespaceSchemaLocation property

Because if you use namespaces, then using selectSingleNode (XPath) adds the namespace of the node element,

The XPath match has changed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.