开发者

Dot net 3.5:how to enable intellisense while writting xml file refering to defined schema?

开发者 https://www.devze.com 2022-12-12 17:18 出处:网络
I have defined a xml schema as below <?xml version=\"1.0\" encoding=\"utf-8\"?> <xs:schema id=\"PacketTemplate\"

I have defined a xml schema as below

<?xml version="1.0" encoding="utf-8"?>

<xs:schema id="PacketTemplate"
targetNamespace="http://tempuri.org/PacketTemplate.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/PacketTemplate.xsd"
xmlns:mstns="http://tempuri.org/PacketTemplate.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:group name="packetTemplate">
  <xs:sequence id="packetTemplateSequence" >

   <xs开发者_JAVA百科:element name="packetType" maxOccurs="1" minOccurs="1" nillable="false" >
    <xs:complexType >
      <xs:attribute name="packetCode" type="xs:string" use="required"></xs:attribute>
      <xs:attribute name="packetTypeIncoming" type="xs:boolean" use="required"></xs:attribute>    
    </xs:complexType>
  </xs:element>
  <xs:element name="packetFieldInfo" minOccurs="1" maxOccurs="unbounded">
    <xs:complexType>
      <xs:attribute name="fieldName" type="xs:Name" use="required"></xs:attribute>
      <xs:attribute name="fieldNumber" type="xs:integer" use="required"></xs:attribute>
      <xs:attribute name="conversionCode" type="xs:integer" use="required"></xs:attribute>
      <xs:attribute name="fieldInUse" type="xs:boolean" use="required"></xs:attribute>

     </xs:complexType>
  </xs:element>
</xs:sequence>

now when i write xml file corresponding to this schema i am not able to use intellisense features like it should show all of possible tags in my file?

Beside that what should i do so that this xml file refer the schema file i have defined? Xml file is as below.

    <?xml version="1.0" encoding="utf-8" ?>
    <packetTemplate>
       <packetType packetCode="601" packetTypeIncoming="123" fieldInUse="true">
       </packetType>
    </packetTemplate>


Another way to validate your XML with your XSD is to specify the XSD when you use msxml, and then you don't have to mark up your XML. I don't know if there is a real advantage going one way or the other.


In Visual Studio you can open the *.xml file and in the properties window you can specify the schema file in the property Schemas.

That way Visual Studio should provide Intellisense, assuming the provided schema is valid.

You can check the W3Schools examples in how to create a XML schema.


For future references: the posted schema is not a well-formed XML: most likely in the publishing process, the last two lines were truncated.

With that fixed, the intellisense will not work since the schema defines a group as opposed to an element. Changing xs:group to xs:element, then following the answer describing the Visual Studio setup, should get one working.

One more thing: the sample XML file as posted is not valid, since at least one packetFieldInfo elements also needs to be in.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号