Filter XMLNodeList using xPath & Wildcard characters

Related searches

I have "XML" as below:

<ParentNode>
    <ChildNode id="1" Display_Name="ABC"/>
    <ChildNode id="2" Display_Name="DEF"/>
    <ChildNode id="3" Display_Name="DAX"/>
    <ChildNode id="4" Display_Name="LAM"/>
    <ChildNode id="5" Display_Name="PKR"/>
    <ChildNode id="6" Display_Name="UYA"/>
</ParentNode>

I want to get list of all the Nodes in XMLNodeList in C# using xPath having "A" [regardless of capitals or small] in Display_Name attribute.

What I've tried is:

root.SelectNodes("descendant-or-self::*[contains(@DISPLAY_NAME,'end')]")

Here, root is containing my XML and it is an object of XMLDocument.

Also, how can I make this filter by ignoring either Display_Name is in small letters or capital letters.

"I want to get list of all the Nodes in XMLNodeList in C# using xPath having "A" [regardless of capitals or small] in Display_Name attribute. "

Nature of XML and XPath is case-sensitive. There is no pretty way to do case-insensitive matching using XPath (at least in XPath 1.0, version that is supported by .NET). One known way is using translate() to convert Display_Name value to lower-case before doing further comparison, something like this (see related post) :

var xpath = @"//*[
                contains(
                    translate(@Display_Name
                              ,'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                              ,'abcdefghijklmnopqrstuvwxyz'
                    )
                    ,'a'
                )
            ]";
var result = root.SelectNodes(xpath);

XmlNode.SelectNodes Method (System.Xml), You can use XPath to find a single, specific node or to find all nodes that match The SelectNodes method returns an XmlNodeList that contains the The examples above start the XPath query at the document element. Remarks. XPath expressions can include namespaces. Namespace resolution is supported using the XmlNamespaceManager.If the XPath expression includes a prefix, the prefix and namespace URI pair must be added to the XmlNamespaceManager.

Try with below XPath

/ParentNode/ChildNode/@Display_Name

To get result for both

Above XPath will return you all results of ChildNode. Now iterate this XPath to extract all results

Hope it will help you :)

Select Nodes Using XPath Navigation, Hello I am having trouble with xpath in xmlnode elements, here is an example of what I mean, here is a very simple xml example: <?xml� Tag: c#,xml,xpath,xmldocument,xmlnodelist. I have Xml that I filter using XPath (a query similar to this): c#,xml,xpath,xmldocument,xmlnodelist I have Xml that I

Use OuterXml method.

Try this:

//Load Data     
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);

//Go the xPath
XmlNode titleNode = xmlDoc.SelectSingleNode(xPath);

//Get the OutXml (You dont need to use a new variable)
string nodeValue = titleNode.OuterXml;

//Load this string as a new XmlDocument and use the second xPath
XmlDocument xmlDoc2 = new XmlDocument();
xmlDoc2.LoadXml(nodeValue);
titleNode = xmlDoc.SelectSingleNode(xPath2);

Xpath cannot filter from XmlNode?, This example shows how to select nodes from XML document by attribute value. Use method XmlNode.SelectNodes to get list of nodes selected by the XPath� I have Xml that I filter using XPath (a query similar to this): I want to create a new XmlDocument instance from the XmlNodeList generated above. At the minute

Select XML Nodes by Attribute Value [C#], To find nodes in an XML file you can use XPath expressions. Method XmlNode. SelectNodes returns a list of nodes selected by the XPath string. Method XmlNode. The following example explains how to use XPath with XmlDocument and select XML nodes by Attribute values. The XML file is loaded into an XmlDocument and then using XPath all the nodes where City attribute has value London are fetched as XmlNodeList.

Select XML Nodes by Name [C#], Namespaces in XPath Expressions. XPath expressions can include namespaces. Namespace resolution is supported using the XmlNamespaceManager.If the XPath expression includes a prefix, the prefix and namespace URI pair must be added to the XmlNamespaceManager, and the XmlNamespaceManager is passed to the SelectNodes(String, XmlNamespaceManager) or SelectSingleNode(String, XmlNamespaceManager) method.

XPath Tutorial XPath Introduction XPath Nodes XPath Syntax XPath Axes XPath Operators XPath Examples XSLT Tutorial XSLT Introduction XSL Languages XSLT Transform XSLT <template> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XSLT Apply XSLT on the Client XSLT on the Server XSLT Edit XML XSLT Examples XQuery Tutorial

Comments
  • Hi @har07, what is the significance of -> ,'a' .. Just curious
  • @ShubhamJain from the quoted section : "...using xPath having "A" [regardless of capitals or small] in Display_Name attribute"
  • But how to make it filter with wild search in all the ChildNodes?
  • And as u suggested, I've tried docGetInternal.SelectNodes("/DISPLAY_TABLE_FIELDS_LOOKUP_TABLE/DISPLAY_TABLE_FIELDS_LOOKUP_ROW[contains(.,'end')]"); but it is not working in my case either.