繁体   English   中英

XSD 架构验证错误:不得包含“<”字符

[英]XSD Schema Validation Error : must not contain the '<' character

我的 XSD 文件:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="sample">
        <xs:complexType>
            <xs:attribute type="xs:string" name="synopsis"/>
            <xs:attribute type="xs:string" name="genre"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

XML文件:

<asset 
synopsis="A romantic affair.<br><br>Contains one use of stronand moderate sex<br><br>Buy it" genre="Drama"/>

代码:

// javax.xml.validation.Validator;
validator.validate(new StreamSource(new ByteArrayInputStream(xmlContent.getBytes(UTF_8))));

得到以下错误:

java.lang.AssertionError: XML Validation Error :The value of attribute "synopsis" associated with an element type "asset" must not contain the '<' character.

任何线索如何在 xml 属性值中允许<>字符?

<转义为&lt; 在 XML 属性值中。

可选地,为了对称,escape > as &gt; 在 XML 属性值中。

另请参阅简化的 XML 转义

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM