all groups > dotnet xml > july 2005 >
You're in the

dotnet xml

group:

SelectNodes starts-with XPath help


SelectNodes starts-with XPath help Larry Viezel
7/22/2005 3:43:23 PM
dotnet xml:
I have the following XML:

<folder name="global">
<folder name="_images">
<file name="creative_apply_txt.jpg" />
<file name="creative_culture_txt.jpg" />
<file name="push_btn_submit.gif" />
</folder>
<folder name="en">
<folder name="_images">
<file name="creative_apply_txt.jpg" />
<file name="creative_home_txt.jpg" />
<file name="header_email_notice.gif" />
</folder>
</folder>
</folder>

And I do the following call in my C# application:
XMLImageFileNodeList = XMLDirectoryStructure.SelectNodes(strXPath);

I want to get the node that represent files in the "en" folder that
start with "creative_". I am trying the XPath in two different ways,
neither of which is returning a result:

/folder[@name = 'global']/folder[@name = 'en']/folder[@name =
'_images']/file[starts-with(@name , 'creative_')]

/folder[@name = 'global']/folder[@name = 'en']/folder[@name =
'_images']/file/@name[starts-with(. , 'creative_')]

I've never really worked with the starts-with function before. Am I
doing it right or am I way off base?

Larry Viezel
Re: SelectNodes starts-with XPath help Bjoern Hoehrmann
7/23/2005 1:05:58 AM
* Larry Viezel wrote in microsoft.public.dotnet.xml:
[quoted text, click to view]

This is correct.

[quoted text, click to view]

This is not, you select the @name attributes, not the element
nodes you are interested in.

[quoted text, click to view]

It's seems your problem is elsewhere. If simple queries like "//file"
do not work either you might have a problem with XML namespaces.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
AddThis Social Bookmark Button