Friday, February 23, 2007

Preparing Dataset for XSLT

To apply XSLT on XML, the xsi namespace needs to be set. This is a way to set the namespace for an XML generated from Dataset.GetXml string xmlnsNS = ""; string xsiNS = ""; XmlDataDocument xmlDocument = new XmlDataDocument(); xmlDocument.LoadXml(ds.GetXml()); xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "utf-8", "yes"), xmlDocument.DocumentElement); XmlAttribute attributeNode = xmlDocument.CreateAttribute("xmlns", "xsi", xmlnsNS); attributeNode.Value = xsiNS; xmlDocument.DocumentElement.SetAttributeNode(attributeNode); xmlDocument.Save("prepared.xml");