12月2日开发记录

xsd.exe反串行化及XML命名空间问题

12月2日

RecordType类的metadataField是一个XmlElement类形。需要将存放资源信息的实例进行串行化生成XmlElement类。今天还没有找到比较好的解决办法。
在用xsd.exe反串行化oai_dc.xsd生成oai_dcType的过程中遇到了下述问题,google: xsd.exe import 得到答案:

Support of import in xsd.exe
I was trying to create a C# class with xsd.exe from an schema that imports others schemas like that xsd.exe /c schema.xsd and it fails miserably reporting an error like "The datatype 'xxx' is missing.". Basically xsd.exe doesn't resolve the schemaLocation attribute.
Dare Obasanjo's article addresses the problem, and Scott Hanselman had the same problem -and solved it-.
The solution isn't very nice, but at least it's simple. You have to tell xsd.exe all the schema referenced, xsd.exe /c schema.xsd importedSchema1.xsd importedSchema2.xsd
(同时在查阅MSDN时了解到Schema <import>和<include>之区别)

最后将这个命令改成 xsd /c oai_dc.xsd simple....xsd xml.xsd /language:CS

照办后可以生成类,但还是报错:Schema could not be validated。
由这个类生成的metadata XML的根节点是这样的
<dc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.openarchives.org/OAI/2.0/oai_dc/">
下面是理想的格式
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
子节点的样子是:
<title xmlns="http://purl.org/dc/elements/1.1/">An Introductory Book To The OAI-PHM</title>
理想的是:
<dc:title>Optimizing The Final Cost In Distribution Networks Under Fuzzy Restrictions</dc:title>
名称空间比较乱,还不知道怎么解决。

郭提出是否可以不将oai_dcType对象串行化为XmlElement,而赋给RecordType的metadataType,直接编码进XML。这样做不知是否可行,因为它可以不再符合Dublin Core了(没有根节点了)。

有必要对xsd.exe处理schema namespace的方式做进一步了解。emcrook.gif

转载于:https://www.cnblogs.com/wlyu2001/archive/2004/12/04/72885.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值