wly.net

12月2日开发记录

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的方式做进一步了解。

posted on 2004-12-04 20:14  wly  阅读(291)  评论(0编辑  收藏  举报

导航