c#

How to transform XML with LINQ to XML in C#

You can find from the articles: How to use XSL to transform XML content, How to use XslCompiledTransform class to transform XML file in C#, and How to use Xml control to transform XML file to HTML output different ways to change the representation of XML. Although XSL will still continue to be used in a …

Learn more

How to use XslCompiledTransform class to transform XML file in C#

If you want to transform XML file into formatted HTML you can use combination of stylesheet and the XslCompiledTransform class (contained in the System.Xml.Xsl namespace). Note: In the next example will be used stylesheet explained in the article How to use XSL to transform XML content. The next code performs this transformation and saves the result …

Learn more

How to validate an XML document with XML Schemas in C#

You can validate an XML document against a schema, by using built in XmlReader’s validation features. Note: You can find more details about XML schemas from the article How to use XML Schemas in XML document.  You can follow the next steps when performing validation:

1. You need to import the System.Xml.Schema namespace, …

Learn more

How to search XML content with XPath in C#

The GetElementsByTagName() method illustrated in the article How to search XML content with XmlDocument in C# is fairly limited. It allows you to search based on the name of an element only. You can’t filter based on other criteria, such as the value of the element or attribute content. In these cases you can use XPath …

Learn more

How to search XML content with XmlDocument in C#

You can perform a search with the XmlDocument by using  XmlDocument.GetElementsByTagName() method, which  searches an entire document tree for elements that have a specific name and returns an XmlNodeList that contains all the matches as XmlNode objects.

For example, the following code retrieves the title of each Book in the document:

 

// Load the XML file.

string xmlFile = …

Learn more

How to use XML Namespaces with XNamespace class in C#

You can use the XNamespace class to create XML content that uses a namespace. You can find more information about XML namespaces from the article How to use XML Namespaces in XML document. When you want to use XNamespace class you should define an XNamespace object first. Then you should add this XNamespace object to the …

Learn more

How to use XMLTextWriter with XML Namespaces in C#

You can use the XMLTextWriter class to create XML content that uses a namespace. The code lies used to illustrate the idea are taken from the article How to use XMLTextWriter to create an XML document in C#, and you can find more information about XML namespaces from the article How to use XML Namespaces in …

Learn more

How to use XmlTextReader to read XML file as objects in C#

You can use the XmlTextReader class when you want to read a XML document in your code. The XmlTextReader moves through your document from top to bottom, one node at a time. You call the Read() method to move to the next node. In a typical application, you would need to go fishing for the elements …

Learn more

How to use XmlTextReader to read XML file as text in C#

You can use the XmlTextReader class when you want to read a XML document in your code. The XmlTextReader moves through your document from top to bottom, one node at a time. You call the Read() method to move to the next node. This method returns true if there are more nodes to read or false …

Learn more

How to use XmlTextWriter formatting in C#

You can create a XML document, by using the basic XmlTextWriter class. If you want to understand how you can read the  article How to use XMLTextWriter to create an XML document in C#. By default, the XmlTextWriter creates an XML file that has all its elements lumped together in a single line without any helpful …

Learn more