我有这个如何去除子元素中的空名称空间“xmlns =”“”?
XNamespace ns = "http://something0.com";
XNamespace xsi = "http://something1.com";
XNamespace schemaLocation = "http://something3.com";
XDocument doc2 = new XDocument(
new XElement(ns.GetName("Foo"),
new XAttribute(XNamespace.Xmlns + "xsi", xsi),
new XAttribute(xsi.GetName("schemaLocation"), schemaLocation),
new XElement("ReportHeader", GetSection()),
GetGroup()
)
);
它给
<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns:xsi="http://something1.com"
xsi:schemaLocation="http://something3.com"
xmlns="http://something0.com">
<ReportHeader xmlns="">
...
</ReportHeader>
<Group xmlns="">
...
</Group>
</Foo>
但我wan't这个结果,怎么能做到呢? (注意xmlns=""
缺少..)
<?xml version="1.0" encoding="utf-8"?>
<Foo xmlns:xsi="http://something1.com"
xsi:schemaLocation="http://something3.com"
xmlns="http://something0.com">
<ReportHeader>
...
</ReportHeader>
<Group>
...
</Group>
</Foo>
感谢这对我有意义,但我仍然不知道该怎么做。 – radbyx 2012-04-18 08:31:21
我只是想在'Foo'之后像'Always'一样,但在'ReportHeader'和'Group'之后没有任何东西:) – radbyx 2012-04-18 08:37:06
如果我用'Foo'替换'ns.GetName(“Foo”)'',我没有得到'Foo'后的'xmlns =“http://something0.com”',如果这是有道理的话。 (它消除了很多) – radbyx 2012-04-18 08:40:55