Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# XDocument Xsd pattern validation with character $

I have a problem with c# XDocument XSD validation.

The following file is validated well by Xml Spy, but not by .Net (c#)

<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Simple.xsd">
    <Var Name="$Toto"/>
</Root>

Schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="Root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Var">
                    <xs:complexType>
                        <xs:attribute name="Name" type="ST_VariableIdentifier" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
        <xs:simpleType name="ST_VariableIdentifier">
        <xs:restriction base="xs:string">
            <xs:pattern value="$[a-z,A-Z]*"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

An idea?

like image 542
swWork Avatar asked Oct 09 '22 16:10

swWork


1 Answers

This should work!

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Var">
          <xs:complexType>
            <xs:attribute name="Name" type="ST_VariableIdentifier" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="ST_VariableIdentifier">
    <xs:restriction base="xs:string">
      <xs:pattern value="[$][a-z,A-Z]*"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
like image 75
InfantPro'Aravind' Avatar answered Oct 12 '22 00:10

InfantPro'Aravind'