I am creating an XDocument as shown below. The output has xmlns = “” for TestId, LoginData and InterfaceVersion elements. I don’t want xmlns = “” for these elements. How to supress this?
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"))));
Thanks in advance.
XElement nodes don’t automatically inherit their namespaces from their parent elements. You need to specify “aw” namespace for each of the child elements – “TestId”, “LoginData” and “InterfaceVersion” – not only to “TestData”.