Category Archives: XML

How to validate XML with XSD file in asp.net using c#

Here we will learn how to validate XML  with XSD file in asp.net using c# with example. //In below example, we are passing three parameters: //xmlString: XML String //XSDPath: Path of XSD file //NamespaceXML: Namespace of xml public static bool IsValidXml(string xmlString, string XSDPath, string NamespaceXML) { bool isValidXML = true; List<string> errrorMssage = null;… Read More »

XML Serialization and Deserialization in C#

Here we will learn how to implement XML serialization and deserialization in asp.net using c# with example: First, we will do serialization of an object as below example //Pass an object of a class public static string SerializeObject(T Request) { string xmlString = string.Empty; MemoryStream memoryStream = null; XmlSerializer xs = null; XmlTextWriter xmlTextWriter =… Read More »

Remove blank node from XML string

Example: public string UpdateXMLString() { string xmlstr = “<detail><FirstName>John</FirstName><LastName></LastName><age>0</age><mobile>0</mobile><address>0</address><address2>aaa</address2></detail>”; XmlDocument xdoc = new XmlDocument(); XmlDocument xdoc2 = new XmlDocument(); // Creat XML object to store result xdoc.LoadXml(xmlstr); XmlNodeList xn = xdoc.LastChild.ChildNodes; int totalnode = xn.Count; // Total no. of nodes for (int i = 0; i < totalnode; i++) { if (xn[i].InnerText == “0” ||… Read More »

Select and remove Node in XML

In below example, I will show you how to find an empty node and deleted. I will also use the OuterXml  inbuilt function to convert the XML data into string. public string UpdateSaveXML() { string xmlstr = “<Name><FirstName>John</FirstName><LastName>Smith</LastName><LastName2></LastName2><LastName3>xxx</LastName3></Name>”; XmlDocument xdoc = new XmlDocument(); XmlDocument xdoc2 = new XmlDocument(); // Creat XML object to store result xdoc.LoadXml(xmlstr);… Read More »