从XML文件C#获取空间 [英] Get namespace from xml file C#

查看:97
本文介绍了从XML文件C#获取空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上过类似的标题问题,但似乎无法找到正是我要找的,如果有人发现了一个类似的问题好心点我thread.Here是我的问题:



我有开始的像这样的XSD文件:




我需要知道如何编程访问上述文件的命名空间价值的开端。



另外我的解决方案需要是通用的,所以我不能简单地搜索的xmlns:XS 因为命名空间的确切名称可能有不同的名称



我试过以下,但调试 elementNamespace 变量的值时是空白

 的XElement elemet = XElement.Load(@D:\xsd\Response.xsd); 
串elementNamespace = elemet.GetDefaultNamespace()NamespaceName。
System.Diagnostics.Debug.WriteLine(命名空间+ elementNamespace);


解决方案

斯科特Hanselman在如何获得命名空间的文章



http://www.hanselman.com/blog/ GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx


I've browsed the questions with similar titles but cannot seem to find exactly what I'm looking for,if anyone spotted a similar question kindly point me to the thread.Here is my question:

I have an xsd file which starts of like this:

I need to know how to programatically access the namespace value of the above file.

Additionally my solution needs to be generic so I cannot simply search for xmlns:xs because the exact name of the namespace may have a different name

I've tried the following, but when debugging the value of the elementNamespace variable is blank "":

XElement elemet = XElement.Load(@"D:\xsd\Response.xsd");
string elementNamespace = elemet.GetDefaultNamespace().NamespaceName;
System.Diagnostics.Debug.WriteLine("Namespace " + elementNamespace);

解决方案

Scott Hanselman has an article on how to get the namespaces:

http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx

这篇关于从XML文件C#获取空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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