获取XSD元素数据类型 [英] Getting XSD element data type

查看:129
本文介绍了获取XSD元素数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我从您的网站上学到了很多关于XSD和XML的知识。感谢您提供的所有信息。我在下面有一个问题。



我搜索了很多网站和页面,但找不到完成下面的方法。



我正在编写一个C#程序,在程序中我需要读取一个XSD文件并获取每个元素的type =值。例如,我可能有如下元素:



Hi,

I''ve learned a lot about XSD and XML from your site. Thanks for all the information that you put there. I have a question below.

I''ve searched a lot of sites and pages and could not find a way to accomplish the below.

I am writing a C# program and in the program I need to read an XSD file and get the "type=" value for each element. For example I might have an element such as below:

<xs:element name="Amount" minoccurs="0" maxoccurs="1" type="xs:date" xmlns:xs="#unknown">







我想把xs:date保存在字符串变量中。我可以遍历XSD文件并获取所有元素名称但我找不到找到类型的方法。



你能提供一些帮助吗?


谢谢!




I''d like to get the "xs:date" to save in a string variable. I can traverse the XSD file and get all element names but I simply cannot find a way to get to the type.

Can you please provide some help?

Thank You!

推荐答案

关键点是:



1)XSD文件本身是xml文件。



2)可以使用xpath查询xml文件 - 在C#中可以使用xml doc的SelectNodes方法完成。

key points are:

1) XSD file itself xml document.

2) xml files can be queried with xpath - in C# it could be done with SelectNodes method of xml doc.
SelectNodes("//somenode", nsmgr);





3)如您所见,SelectNodes具有nsmgr参数。 (XmlNamespaceManager nsmgr)

如果你想查询xs:namespace中的xsd,你必须添加它:





3)As you see SelectNodes has nsmgr parameter. (XmlNamespaceManager nsmgr)
If you want to query xsd which is in xs: namespace, you have to add it:

nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");



4)获取所有xs的脏xpath:设置了类型属性的元素是:




4) dirty xpath to get all xs:elements with type attributes set is:

//xs:element[@type]







http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx [ ^ ]



http:/ /msdn.microsoft.com/ru-ru/library/system .xml.xmlnamespacemanager.addnamespace(v = vs.95).aspx [ ^ ]


这篇关于获取XSD元素数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆