Search code examples
xmllinq-to-xmlxelement

Insert 'xml:base' into XElement root


How can one insert the 'XML Base' attribute/namespace (http://en.wikipedia.org/wiki/XML_Base) into the root of an XElement or XDocument?

<feed xml:base="someurl.com">...</feed>

And, do that without messing up the whole XElement (e.g. by it trying to insert the same everywhere else or some related crazy side effect).


Solution

  • This should do the trick:

    element.Root.SetAttributeValue(XNamespace.Xml + "base", "someurl.com") 
    

    (Edit: SetAttributeValue)