Я создаю XDocument с пространствами имен в моем конструкторе, например.Добавить XElement, который использует пространство имен
this.nsXsl = XNamespace.Get("http://www.w3.org/1999/XSL/Transform");
this.doc = new XDocument(
new XElement(nsXsl + "stylesheet", new XAttribute("version", "1.0"), new XAttribute(XNamespace.Xmlns + "xsl", "http://www.w3.org/1999/XSL/Transform"),
new XElement(nsXsl + "output", new XAttribute("method", "xml"), new XAttribute("indent", "yes"), new XAttribute("encoding", "UTF-8")),
new XElement(nsXsl + "strip-space", new XAttribute("elements", "*")))
);
Этот документ имеет правильную структуру и выглядит так, как будто я хочу.
Но у меня есть функция, как:
private XElement createTemplate(string match, string node, string fork, string select)
{
return new XElement(this.nsXsl + "template", new XAttribute("match", match), new XElement(node,
new XElement(this.nsXsl + fork, new XAttribute("select", select))));
}
эта функция возвращает XElement следующей структуры:
<template match="/shiporder/shipto" xmlns="http://www.w3.org/1999/XSL/Transform">
<Line1>
<apply-templates select="city" xmlns="" />
</Line1>
</template>
Но мне нужен XElement как:
<xsl:template match="/shiporder/shipto">
<Line1>
<xsl:apply-templates select="city" />
</Line1>
</xsl:template>
Изменения вы хотите только косметический, и как/когда новый XElement прилагаются к XDoc? –
@HenkHolterman до сих пор у меня есть список шаблонов и добавлю их как 'foreach (XElement elem в шаблонах) { doc.Add (elem); } ' – StellaMaris
Тогда проблема разрешится сама. Не делай ничего. –