|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace LearningMahesh.DynamicIOStream.Xml
{
public class XmlNamespaceRemover
{
public XmlNamespaceRemover() { }
public static XElement RemoveAllNamespaces(XDocument xDocumentSource)
{
Stream docStream = new MemoryStream();
xDocumentSource.Save(docStream);
docStream.Position = 0;
Stream outputStream = new MemoryStream();
outputStream.Position = 0;
XPathDocument xPathDocument = new XPathDocument(docStream);
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
XslTransform myXslTransform;
myXslTransform = new XslTransform();
XmlReader xsltReader =
XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("LearningMahesh.DynamicIOStream.Xml.StripNamespace.xslt"));
myXslTransform.Load(xsltReader);
XsltArgumentList xsltArgList = new XsltArgumentList();
myXslTransform.Transform(xPathNavigator, xsltArgList, outputStream);
outputStream.Position = 0;
XDocument finalDocument = XDocument.Load(outputStream);
XElement root = finalDocument.Root;
return root;
}
public static XElement RemoveAllNamespaces(XElement xElementSource)
{
Stream docStream = new MemoryStream();
xElementSource.Save(docStream);
docStream.Position = 0;
Stream outputStream = new MemoryStream();
outputStream.Position = 0;
XPathDocument xPathDocument = new XPathDocument(docStream);
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
XslTransform myXslTransform;
myXslTransform = new XslTransform();
XmlReader xsltReader =
XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("LearningMahesh.DynamicIOStream.Xml.StripNamespace.xslt"));
myXslTransform.Load(xsltReader);
XsltArgumentList xsltArgList = new XsltArgumentList();
myXslTransform.Transform(xPathNavigator, xsltArgList, outputStream);
outputStream.Position = 0;
XDocument finalDocument = XDocument.Load(outputStream);
XElement root = finalDocument.Root;
return root;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Started my software development career in December 2007. Having 4+ years of experience in C#. More interested to learn deeper and share on Design Pattern, Parallel and Dynamic programming.
Started my career as PERL developer for few months and then moved to VC++ and then to C#. When i moved from Procedure oriented programming to Object oriented programming, i really enjoyed and appreciated the OOPS concepts.
Explored most of the language features of C# 3.5 and 4.0. In my current assignments, working on Biz Talk and WCF.