Add namespace and alias to existing xml
问题 I am using the code below to change a namespace in an existing XML message in a BizTalk pipeline component. This works but how would I add a namespace alias to the document as well. XNamespace toNs = "http://hl7.org/fhir/Encounters"; XElement doc = XElement.Parse(xmlIn); doc.DescendantsAndSelf().Attributes().Where(a => a.IsNamespaceDeclaration).Remove(); var ele = doc.DescendantsAndSelf(); foreach (var el in ele) el.Name = toNs + el.Name.LocalName; return new XDocument(doc); 回答1: You can