XML:isnil无效元素

我有以下XSD片段: <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:simple类型>XML:isnil无效元素

和相应的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>

我试图验证SSN在这个XML。但我收到以下错误:

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.

如何解决此问题?我尝试过各种各样的变化。

我试过XSI更新,但这给了我这个错误,XSI在我的XML文件中指定nowhwere,所以我不认为我可以引用它:

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) 

布莱恩,我现在想你的XSI代码,但这给了我这个错误:

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.

它给了我同样的错误,当我包括样式表。

回答:

您是否尝试引用xsi?

<SSN xsi:nil="true" /> 

你也需要有XSI在样式表头

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

引用...在你的XML根节点对应的值(从http://www.w3schools.com/schema/schema_schema.asp拍摄)。

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

以上是 XML:isnil无效元素 的全部内容, 来源链接: utcz.com/qa/258735.html

回到顶部