我正在创建一个XDocument,如下所示。对于TestId、LoginData和InterfaceVersion元素,输出的xmlns = "“。我不希望这些元素使用xmlns = "“。如何抑制这一点?
XNamespace aw = "http://test.com/xml/DatabaseService/TestData";
XDocument xw = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement(aw + "TestData", new XAttribute("version", "1.0"),
new XElement("TestId", new XAttribute("Id", strPublishedId)),
new XElement("LoginData", new XAttribute("User", "none"), new XAttribute("Password", "nothing"), new XAttribute("Domain", "")),
new XElement("InterfaceVersion", new XAttribute("Major", "1"), new XAttribute("Minor", "0"))));提前谢谢。
发布于 2012-03-22 07:42:29
XElement节点不会自动从其父元素继承其名称空间。您需要为每个子元素- "TestId“、"LoginData”和"InterfaceVersion“-指定"aw”名称空间,而不仅仅是"TestData“。
https://stackoverflow.com/questions/9813869
复制相似问题