
Visual Studio automatically inserts the appropriate XML tags: On the line above the class, property, method, or whatever you are documenting, type three forward slashes. If you are not familiar with XML Documentation Comments (or just XML Comments), you create them differently depending on the language you are using. I’m sure all developers know this at this point, but did you know that you can modify the set of valid tags? You can document your classes, properties, methods, and so on using XML tags. This post separates the first step to provide a more straightforward example. NOTE: This post was created based on a prior post that included both finding a node and adding new nodes. NOTE: The XElement properties and methods work in VB as well.
#مشكلة system.core vb net 2010 code#
The C# code uses the XElement properties and methods. The next set of code can be done using LINQ or using Lambda expressions. This code first loads the XML file containing the XML. ‘ Be sure to set a reference to System.Core and ĭim states As XElement = XElement.Load("testXML.xml")ĭim query = From r As XElement In states… _įoundNode = states….Where(Function(r) = _ Where r.Attribute("name").Value = "Milwaukee"įoundNode = states.Descendants("Region"). Var query = from XElement r in states.Descendants("Region") XElement states = XElement.Load("testXML.xml") Be sure to set a reference to System.Core and The code to find the node for the Milwaukee region is as follows: NET framework 3.5 or higher, you can find the node using Linq to XML or by using Lambda expressions.Īs with many of my prior XML examples, the XML string is as follows: The RegEx.Unescape takes care of unescaping the characters for viewing.Ī common requirement with an XML file is to find a particular node. The RegEx.Escape takes care of escaping the necessary characters for the XML string. You can escape it in the string by doubling it (""). The only character that you still need to escape is the quotation mark. This code results in the following MessageBox: "Ampersand: &, Apostrophe: ‘, Quote: "" " & _ĭim description As String = Regex.Unescape(myXML.Value) NOTE: Be sure to import the namespace.ĭim s As String= "This is a product that has special characters: " & _ This works, but is not very nice to look at, especially if you are not familiar with HTML character entities.Īnother option is to use the RegularExpression Escape and Unescape methods. To get this code to compile, replace the problematic symbols with HTML character entities:Īmpersand: &, Apostrophe: ‘, Quote: " This is a product that has special characters: It tries to interpret the less than and greater than signs as XML elements. NOTE: All of the code in this post is in Visual Basic since C# does not directly support XML literals.įor example, the following code will not compile. If you just type these characters in to your XML literal, your application won’t understand them. In XML, there are several characters that have special meaning, such as the less than () and quotation mark ("). Use this technique any time you need to retrieve a set of nodes from an XML file. The second set of code combines the set of Linq to XML statements into one for a more condensed version of the code. The enumeration is then converted to a list so it can be sorted and assigned as a DataSource. NOTE: You can also use the XElement methods in VB as well. Again, the C# code uses the XElement methods and the VB code uses XML literals. Only the name of the regions are needed, so the next statement selects the name attribute. The C# code uses the XElement methods and the VB code uses XML literals. The code first finds the set of region elements. (r => r.Attribute("name").Value).ToList() ĭim regionEnumeration = regionElements.Select(Function(r) regionList As List(Of String) = regionEnumeration.ToListĭim regions As List(Of String) = doc….Select _ List regions = doc.Descendants("Region").Select List regionList = regionEnumeration.ToList() Var regionEnumeration = regionElements.Select Var regionElements = doc.Descendants("Region") Starting with a simple example, let’s find the set of all regions and display them in a combo box. Here is the XML we will use in this example:

NET Framework version 3.5 or later, you can use Linq to XML to retrieve a set of nodes. In this example, the set of nodes are displayed in a ComboBox. You can then process those nodes as needed in your application. In this post, I expand on that topic to find a set of nodes.
#مشكلة system.core vb net 2010 how to#
In this prior post, I demonstrated how to find a node in an XML string.
