XPATH CONTAINS

I filter/search an xml-file, and this works:
XmlDataSource1.XPath = "NewDataSet/tbl_arenden_kw[contains(@rubrik_kw,'" + TextBox1.Text + "')]"

I try to filter/search in all nodes, but it does not work (no records):
XmlDataSource1.XPath = "NewDataSet/tbl_arenden_kw/@*[contains(.,'" + TextBox1.Text + "')]"

Do you have any ideas ?
Thanks in advance

Clas

[397 byte] By [Clas] at [2007-12-17]
# 1
"NewDataSet/tbl_arenden_kw/@*[contains(.,'" + TextBox1.Text + "')]" - searches/filters attributes of tbl_arenden_kw elements

"NewDataSet/tbl_arenden_kw//*[contains(.,'" + TextBox1.Text + "')]" - searches/filters elements located inside of tbl_arenden_kw elements

TheXMLMan at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2
changed to //* but the result is "emty".......

Search: "snow"
XmlDataSource1.XPath = "NewDataSet/tbl_arenden_kw//*[contains(.,'" + TextBox1.Text + "')]"
Result: No record, emty (I use a Repeater)

When I changed to:
XmlDataSource1.XPath = "NewDataSet/tbl_arenden_kw[contains(@arendetext, '" + TextBox1.Text + "']"
Result: A powerful......
Part of XML-file:
<NewDataSet>
<tbl_arenden_kw>
<rubrik_kw>WEATHER</rubrik_kw>
<rubrik_egen>Winter storm brings snow to Colorado mountains</rubrik_egen>
<arendetext>A powerful snowstorm that dropped up to 20 inches of snow in parts of Colorado</arendetext>
</tbl_arenden_kw>
</NewDataSet>

Clas at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3
XPATH :
Search text in all elements (tbl_arenden_kw) in all attribute names

This do not work
XmlDataSource1.XPath = "NewDataSet/tbl_arenden_kw[contains(@*, '" + TextBox.Value + "']"
Or
XmlDataSource1.XPath = "NewDataSet/tbl_arenden_kw/@*[contains(.,'" + TextBox1.Text + "')]"

xsl:template match="/">

<xsl:for-each select="NewDataSet">

<xsl:element name="NewDataSet">
<
xsl:for-each select="tbl_arenden_kw">
<
xsl:element name="tbl_arenden_kw">

<xsl:attribute name="rubrik_kw">
<
xsl:value-of select="rubrik_kw"/>
</
xsl:attribute>

<xsl:attribute name="rubrik_egen">
<
xsl:value-of select="rubrik_egen"/>
</
xsl:attribute>

<xsl:attribute name="arendetext">
<
xsl:value-of select="arendetext"/>
</xsl:attribute>

Clas at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 4
the following xpath will return all tbl_arenden_kw-elements that have a childelement arendetext that contains 'snow'



//tbl_arenden_kw[contains(arendetext, 'snow')]

//tbl_arenden_kw matches all tbl_arenden_kw elements
use [] to restrict the selected nodes

the xpath contains function accepts only strings as a parameter, so if you want to 'search' multiple child-elements, the solution is to create an or-statement

e.g.


//tbl_arenden_kw[contains(arendetext, 'snow') or contains(rubrik_egen, 'snow')]

JoostPloegmakers at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 5
Yes, it works, but I must use @

XmlDataSource1.XPath = "//tbl_arenden_kw[contains(@arendetext, '" + TextBox1.Text + "') or contains(@rubrik_egen, '" + TextBox1.Text + "')]"

Thanks, The XML Man and Joost Ploegmaster for your help !

Clas at 2007-9-9 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified