请教如何对xml文件进行验证(使用DTD)

jjstar 2003-12-15 05:45:06
验证文件名为YSFPDKLJK.dtd,是上层系统统一定义的,内容如下,
<?xml version="1.0" encoding="GBK"?>
<!--
运输发票抵扣联申报数据DTD
-->
<!--以下部分为系统统一定义-->
<!ELEMENT SCHEMA (TAXPAYER)*>
<!ATTLIST SCHEMA
NAME CDATA #REQUIRED
CHSNAME CDATA #REQUIRED
SSSQ CDATA #REQUIRED
CRC CDATA #REQUIRED
>
<!--以下部分根据YSFPDKLTransfer.xml定义-->
<!ELEMENT TAXPAYER (RECORDS)>
<!--TAXPAYER属性部分由系统统一定义-->
<!ATTLIST TAXPAYER
SWSBH CDATA #REQUIRED
NSRMC CDATA #REQUIRED
SBRQ CDATA #REQUIRED
RECORDCOUNT CDATA #REQUIRED
NSRLX CDATA #REQUIRED
KPRDM CDATA #REQUIRED
KPRMC CDATA #REQUIRED
>
<!ELEMENT RECORDS (RECORD)*>
<!ELEMENT RECORD EMPTY>
<!ATTLIST RECORD
FPZL CDATA #REQUIRED
FPHM CDATA #REQUIRED
KPRQ CDATA #REQUIRED
YSDWMC CDATA #REQUIRED
YSDWSWSBH CDATA #REQUIRED
YSDWSWJGMC CDATA #REQUIRED
YSDWSWJG CDATA #REQUIRED
YFJE CDATA #REQUIRED
YXDKYFJE CDATA #REQUIRED
JXSE CDATA #REQUIRED
>


我的程序生成的xml文件如下

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE SCHEMA SYSTEM "YSFPDKLJK.dtd">
<SCHEMA NAME="YSFPDKL" CHSNAME="增值税运输发票抵扣清单" SSSQ="200311" CRC="CRC200311_21010500003.XML">
<TAXPAYER SWSBH="21010500003" NSRMC="纳税人007" SBRQ="2003-12-15" RECORDCOUNT="0" CJLX="DKZK" CJRDM="21010500003" CJRMC="纳税人007">
<Records/>
</TAXPAYER>
</SCHEMA>

请问如何在.net中调用dtd对我的文件进行验证?
...全文
213 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
snakeyin 2003-12-16
到了
回复
inethax 2003-12-16
学习->up
回复
saucer 2003-12-16
try something like

using System.Xml;
using System;


string sFile = "TestVal.xml";
XmlTextReader txtreader = new XmlTextReader(sFile);
XmlValidatingReader reader = new XmlValidatingReader(txtreader);
txtreader.WhitespaceHandling = WhitespaceHandling.None;


XmlUrlResolver resolver = new XmlUrlResolver();
reader.XmlResolver = resolver;


XmlDocument xmldoc = new XmlDocument();

try
{
xmldoc.Load(reader);
Console.WriteLine(xmldoc.DocumentElement.ChildNodes.Count);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
txtreader.Close();
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2003-12-15 05:45
社区公告
暂无公告