我正在系统中进行XML验证,并且已经通过XmlReader实现了此功能,但是我想使用EMPTY STRING值验证#Required属性。有没有办法在DTD属性中实现这一点?
DTD:
<!ATTLIST TEST
pUsername CDATA #REQUIRED (...SHOULD NOT BE AN EMPTY STRING)
pTestAttrib CDATA #REQUIRED (...SHOULD NOT BE AN EMPTY STRING)
>
XML:
<TEST pUsername="" pTestAttrib=""> (I want to validate if this attribute value is empty string)
C#:伪代码
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationEventHandler += delegate (object sender, ValidationEventArgs args) { messageBuilder.AppendLine(args.Message); };
settings.ValidationType = ValidationType.DTD;
settings.DtdProcessing = DtdProcessing.Parse;
using (XmlReader reader = XmlReader.Create(stream, settings))
{
do
{
}
while (reader.Read());
}
答案 0 :(得分:0)