如何使用c#XElements以xml格式添加冒号 [英] how to add colons in xml format using c# XElements
本文介绍了如何使用c#XElements以xml格式添加冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个c#代码:
hi i have this c# code :
new XElement("Zone",
new XElement("gmlBoundedBy",
new XElement("gmlBox",
new XElement("gmlCoord1",
new XElement("gmlX", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_X1),
new XElement("gmlY", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_Y1)
),
new XElement("gmlCoord2",
new XElement("gmlX", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_X2),
new XElement("gmlY", Planaanvraag_Zone_gml_boundedBy_gml_Box_gml_coord_gml_Y2)
)
)
),
和i想要这个输出我用过所有东西,但它不起作用:
and i want this output i used everything but it is not working :
<pre lang="xml"><gml:boundedBy>
<gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#31300">
<gml:coord>
<gml:X>144287.60</gml:X>
<gml:Y>170609.06</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>144485.51</gml:X>
<gml:Y>170912.33</gml:Y>
</gml:coord>
</gml:Box>
</gml:boundedBy>
<pre lang="HTML"><pre lang="HTML">
有人能帮我如何以xml格式添加冒号吗?
can anyone help me how to add colons in xml format ?
推荐答案
根据您的需要进行更改。您可以在输出中看到命名空间添加:
Change according to your need. You can see the namespace is added with : in the output.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
XNamespace gml = "http://www.samplens.com";
XElement x = new XElement(gml + "Box", new XAttribute(XNamespace.Xmlns + "gml", gml.NamespaceName), new XElement(gml + "coord","some content" ));
Console.WriteLine(x);
Console.ReadLine();
}
}
}
这篇关于如何使用c#XElements以xml格式添加冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文