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.