Menu
  • HOME
  • TAGS

XNamespace in C#

c#,xnamespace

Specify "url" namespace for the element you don't want to have an empty xmlns. This clears all the xml namespaces except for the root element: var ns = XNamespace.Get("url"); XDocument requestXMl = new XDocument( new XElement(ns+"WEB_REQUEST", new XElement(ns+"HTTP_HEADER_INFORMATION", new XElement(ns+"DEFINED_HEADERS", new XElement(ns+"HTTP_DEFINED_REQUEST_HEADER", new XElement(ns+"ItemNameType", "RequestDate"), new XElement(ns+"ItemValue", _currentTime) ), new...

C# with XDocument and xsi:schemaLocation

c#,xml,linq-to-xml,linq-to-xsd,xnamespace

You need to use xmlns XNamespace for all elements, because that is default namespace and it is declared at root level element. Note that descendant elements inherit ancestor default namespace implicitly, unless otherwise specified : XDocument xmlDocument = new XDocument( new XElement(xmlns + "MyNode", new XAttribute(xsi + "schemaLocation", schemaLocation), new...