结肠XML元素名称 [英] xml element name with colon

查看:186
本文介绍了结肠XML元素名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作对一个第三方的XML API。他们定义类似于以下所需的XML结构。

I'm working against a 3rd party xml api. They have defined a required xml structure similar to the following.

<ns1:E xmlns:ns1="schema">
<ns1:B>
	<ns2:S>
		<ns2:V>
			<ns2:Bl />
		</ns2:V>
	</ns2:S>
</ns1:B>
</ns1:E>

有一个与我需要把这个XML格式的信息SQL​​表。我有一个LINQ to SQL的接口来获取数据,我使用的是的System.Xml 来创建一个XML文档。

There is a SQL table with the information that I need to put into this xml format. I have a LINQ to SQL adapter to get the data and I'm using a System.Xml to create an XML document.

XmlDocument.CreateElement("ns1:E"); etc

这工作得很好,只要我从元素名称中删除冒号。用冒号,结肠仅右手侧是在元素名称。我知道冒号是一个没有没有,但我没有在什么第三方API在决定着任何控制。

This works fine as long as I remove the colons from the element names. With the colons, only the right hand side of the colon is in the element name. I know colons are a no-no but I don't have any control over what the 3rd party api is dictating.

我有哪些选择获取解决此问题?是否有强迫冒号到元素名称的任何有效的方式?我没有使用的XMLDocument 但不知道还有什么其他方法让我在那里。

What are my options for getting around this? Are there any useful ways of forcing the colons into the element names? I don't have to use XMLDocument but not sure what other method will get me there.

更新:我意识到,&LT; NS1:引用一个命名空间。是的,还有2.当写出来的XML,我可以把它的工作,如果我说 -

UPDATE: I realize that the <ns1: refers to a namespace. And yes, there are 2. When writing out the XML, I can make it work if I say -

 XmlDocument.CreateElement(ns1:E", "http://schema);

然而,这样做的XML输出​​为

However, the XML output of this is

<ns1:E xmlns:ns1="http://schema">

如果我只是说 XmlDocument.CreateElement(NS1:E); 没有URI,那么输出就是&LT; E&GT; 。我不希望输出有模式的参考,但我也需要有preFIX。我想达到的结果是根本&LT; NS1:E&GT; 。这两个namspaces是在这我想将意味着我将不得不在每一个节点宣布其顶部声明。

If I just say XmlDocument.CreateElement("ns1:E"); with no uri, then the output is just <E>. I don't want the output to have the schema reference but I do need to have the prefix. The result I want to achieve is simply <ns1:E>. Both namspaces are declared at the top which I would think would mean I would have to declare them at every node.

推荐答案

好了,在这儿呢。

XmlDocument.CreateElement("prefix", "name", "uri");

在这里引用,如果它可以帮助别人:<一href="http://msdn.microsoft.com/en-us/library/c22k3d47.aspx">http://msdn.microsoft.com/en-us/library/c22k3d47.aspx [1]

这篇关于结肠XML元素名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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