// convert string to stream
XmlDocument xmlDoc = new XmlDocument();
byte[] byteArray = Encoding.ASCII.GetBytes(xmlResp);
MemoryStream stream = new MemoryStream(byteArray);
xmlDoc = ConvertStreamToXMLDocument(stream);
private XmlDocument ConvertStreamToXMLDocument(Stream stream)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument = new XmlDocument();
//load into XDocument
XDocument xDocument = XDocument.Load(stream);
//scrub the namespaces out!
xDocument.Descendants().Attributes().Where(x => x.IsNamespaceDeclaration).Remove();
// convert to xml document
using (var xmlReader = xDocument.CreateReader())
{
xmlDocument.Load(xmlReader);
}
// remove default namespace
xmlDocument.LoadXml(xmlDocument.OuterXml.Replace(xmlDocument.DocumentElement.NamespaceURI, ""));
xmlDocument.DocumentElement.RemoveAllAttributes();
return xmlDocument;
}
XmlDocument xmlDoc = new XmlDocument();
byte[] byteArray = Encoding.ASCII.GetBytes(xmlResp);
MemoryStream stream = new MemoryStream(byteArray);
xmlDoc = ConvertStreamToXMLDocument(stream);
private XmlDocument ConvertStreamToXMLDocument(Stream stream)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument = new XmlDocument();
//load into XDocument
XDocument xDocument = XDocument.Load(stream);
//scrub the namespaces out!
xDocument.Descendants().Attributes().Where(x => x.IsNamespaceDeclaration).Remove();
// convert to xml document
using (var xmlReader = xDocument.CreateReader())
{
xmlDocument.Load(xmlReader);
}
// remove default namespace
xmlDocument.LoadXml(xmlDocument.OuterXml.Replace(xmlDocument.DocumentElement.NamespaceURI, ""));
xmlDocument.DocumentElement.RemoveAllAttributes();
return xmlDocument;
}
No comments:
Post a Comment