问题
I've got a webservice that generates some XML.
<Town>
<Countrycode>gb</Countrycode>
<CountryName>United Kingdom</CountryName>
<CleanedAccentCity>Seamill</CleanedAccentCity>
<RegionName>North Ayrshire</RegionName>
<Population>0</Population>
<Distance>0.0497417145329766</Distance>
</Town>
This I added to my Visual Studio 2012 project by Add New Item... XML to schema.
That works great I wind up with an xsd file in my project then in code I can write:
Public Property returnedXML As XElement
..
arr = client.DownloadString("http://host/myservice.asmx/GetTopTownsByLatLon?Latitude=" & p.latitude & "&Longitude=" & p.longitude )
returnedXML = XElement.Parse(arr)
firstChild = returnedXML.Descendants().First
City = firstChild...<City>.Value
etc..
And when I type the .. after firstChild I get intellisense that shows me the attributes in the XML.
Now what I need to do is get another different webservice to give me some other data. So I do the same process, and get my XSD files saved into the project. But, guess what, the intellisense no longer works.
Clearly I need to identify which XSD file needs to be read for the intelisense. Where do I set that?
Here are the two XSD files:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Towns">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Town">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="url" type="xs:string" />
<xs:element name="Distance" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Towns">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Town">
<xs:complexType>
<xs:sequence>
<xs:element name="Countrycode" type="xs:string" />
<xs:element name="CountryName" type="xs:string" />
<xs:element name="CleanedAccentCity" type="xs:string" />
<xs:element name="RegionName" type="xs:string" />
<xs:element name="Population" type="xs:unsignedByte" />
<xs:element name="Distance" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks
回答1:
If there are conflicts between these schemes definitions (like duplicated element definitions etc.), the source is not compiled and intellisense not work.
Can you share both XSD files?
EDIT:
Both XSD has a duplicate elements (<Towns>, <Town> and <Distance>) and no namespace definitions, so there is no way to difference between theirs. In order to works properly you have two ways:
First way: Change these name elements in only one of your XSD, for example
<TownsA>, <TownA>, <DistanceA>:<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="TownsA"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="TownA"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="url" type="xs:string" /> <xs:element name="DistanceA" type="xs:unsignedByte" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType>And keep the second untouched:
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Towns"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="Town"> <xs:complexType> <xs:sequence> <xs:element name="Countrycode" type="xs:string" /> <xs:element name="CountryName" type="xs:string" /> <xs:element name="CleanedAccentCity" type="xs:string" /> <xs:element name="RegionName" type="xs:string" /> <xs:element name="Population" type="xs:unsignedByte" /> <xs:element name="Distance" type="xs:decimal" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>- Second way: Add a different targetNamespaceNamespaces in your schemas in
<xs:schema>:
- Second way: Add a different targetNamespaceNamespaces in your schemas in
First XSD:
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://mynamespace.org/1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
Second XSD:
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://mynamespace.org/2"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
来源:https://stackoverflow.com/questions/22665287/use-two-xsd-schemas-in-visual-studio-2012