XML: isnil invalid element

1.5k views Asked by At

I have the following XSD snippet: <xs:element name="SSN" nillable="true" minOccurs="0"><xs:annotation><xs:documentation>SSN</xs:documentation></xs:annotation><xs:simpleType><xs:restriction base="xs:string"><xs:pattern value="\d{9}"/></xs:restriction></xs:simpleType>

And the corresponding XML:

<xsl version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Provider xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...
  <Patient>
    <ProviderPatientNo>00202000</ProviderPatientNo>
    <LastName>B </LastName>
    <FirstName>Savannah</FirstName>
    <SSN>409850124</SSN>
    <DOB>1998-06-17</DOB>
    <Gender>1</Gender>
    <Race>8</Race>
    <Ethnicity>3</Ethnicity>
    <PhoneAssessment>
      <ProviderPhoneAssessmentId>00F62E2A-B726-4573-B459-E216AC78BA06</ProviderPhoneAssessmentId>
      <CallEndDate>2013-09-16</CallEndDate>
      <CallEndTime>11:30:00</CallEndTime>
      <CallDisposition>5</CallDisposition>
    </PhoneAssessment>
  </Patient>
 <Patient>
    <ProviderPatientNo>00202001</ProviderPatientNo>
    <LastName>C</LastName>
    <FirstName>Kylie</FirstName>
    <SSN isnil="true" />
    <DOB>2003-06-24</DOB>
    <Gender>1</Gender>
    <Race>1</Race>
    <Ethnicity>2</Ethnicity>
    <PhoneAssessment>
      <ProviderPhoneAssessmentId>01089482-E878-4288-B103-A0F28B0A33EC</ProviderPhoneAssessmentId>
      <CallEndDate>2013-09-25</CallEndDate>
      <CallEndTime>18:12:00</CallEndTime>
      <CallDisposition>1</CallDisposition>
    </PhoneAssessment>
  </Patient>
....
</xsl>

I'm trying to validate the SSN in this XML. But I get the following error:

The 'isnil' attribute is not declared.
The 'http://www.tn.gov/mental/Schemas/CrisisAssessment:SSN' element is invalid - The value '' is invalid 
according to its datatype 'String' - The Pattern constraint failed.

How do I fix this? I have tried various variations of this.

I tried the xsi update but this gave me this error and xsi is nowhwere specified in my XML file so I don't think I can reference it:

System.Xml.XmlException: 'xsi' is an undeclared namespace. Line 106, position 10. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg, Int32 lineNo, Int32 linePos) at System.Xml.XmlTextReaderImpl.LookupNamespace(NodeData node) at System.Xml.XmlTextReaderImpl.AttributeNamespaceLookup() at System.Xml.XmlTextReaderImpl.ParseAttributes() at System.Xml.XmlTextReaderImpl.ParseElement() at System.Xml.XmlTextReaderImpl.ParseElementContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o) at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) at System.Xml.Linq.XDocument.Load(String uri, LoadOptions options) at System.Xml.Linq.XDocument.Load(String uri) at CMS.UI.WebForms_ManageDataFiles.ValidateXML(String strXMLInstancePath, XElement& xFileDoc) at CMS.UI.WebForms_ManageDataFiles.Master_UploadButton_Click(Object sender, EventArgs e)

Bryan, I tried your xsi code now, but this gives me this error:

The 'http://www.tn.gov/mental/Schemas/CrisisAssessment:xsl' element is not declared.
The attribute 'http://www.w3.org/2001/XMLSchema-instance:isnil' does not match one of the four allowed 
attributes in the 'xsi' namespace.

It gave me this same error when I included stylesheet.

1

There are 1 answers

4
bryanjonker On BEST ANSWER

Did you try to reference the xsi?

  <SSN xsi:nil="true" />

You also need to have the xsi referenced in your stylesheet header

  <xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

...and the corresponding value in your XML root node (taken from http://www.w3schools.com/schema/schema_schema.asp).

  <Patients xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">