By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,668 Members | 1,606 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,668 IT Pros & Developers. It's quick & easy.

XML Search

P: n/a
Hi Guys,

I know XPath is a good method to search into an xml file but what if
you're looking for a specifc data which could be any where within the xml
file ? Should I consider all possibilities and paths in the xml file ?!!!
Isn't better to have a recurrsive method to traverse the whole tree instead
of passing patterns to "SelectNode" method ?

Let me know if you have experience on this.

Thanks in advace
Newbie
Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
XPath is pretty versatile. Any recurrsive method you might write should be
able to be implemented as an XPath expression, but run faster through XPath.
Can you give us an example, maybe someone could give you a snip to try out.

"C# newbie" <rs****@otxresearch.com> wrote in message
news:#$**************@TK2MSFTNGP09.phx.gbl...
Hi Guys,

I know XPath is a good method to search into an xml file but what if
you're looking for a specifc data which could be any where within the xml
file ? Should I consider all possibilities and paths in the xml file ?!!!
Isn't better to have a recurrsive method to traverse the whole tree instead of passing patterns to "SelectNode" method ?

Let me know if you have experience on this.

Thanks in advace
Newbie

Nov 15 '05 #2

P: n/a
GetElementsByTagName is one way to do it.
"C# newbie" <rs****@otxresearch.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi Guys,

I know XPath is a good method to search into an xml file but what if
you're looking for a specifc data which could be any where within the xml
file ? Should I consider all possibilities and paths in the xml file ?!!!
Isn't better to have a recurrsive method to traverse the whole tree instead of passing patterns to "SelectNode" method ?

Let me know if you have experience on this.

Thanks in advace
Newbie

Nov 15 '05 #3

P: n/a

Hi Richard,

Thanks for your response but it was kind of general. As far as, I know
it works for XML TagNames but I'm looking for data which are in any place of
an xml file not any tag name. Let's say I have an xml file as below and my
program should find any thing like "#19384A" or "center" in below code. Does
the "GetElementsByTagName" works for this too ?

<?xml version="1.0"?>
<Form SurveyName="empty" SurveyID="1" StyleUsage="URL"
xmlns=http://www.yahoo.com SurveyProgrammer="ramsin" DateTime="2/12/2004
5:00:54 PM">
<Params>
<BackgroundColor>#19384A</BackgroundColor>
<LinkColor>#ffffff</LinkColor>
<VisitedLinkColor>#ffffff</VisitedLinkColor>
<TextColor>#ffffff</TextColor>
<Direction>ltr</Direction>
<BackgroundImage>
</BackgroundImage>
<Header>&lt;table width='600' cellspacing='0' callpadding='0' border='0'
align='center'&gt;
</Params>
....
.....
......
......
......
</Form>

Thanks

"Richard T. Ed*****@pwpsquared.net" <re****@pwpsquared.net> wrote in message
news:%2********************@TK2MSFTNGP12.phx.gbl.. .
GetElementsByTagName is one way to do it.
"C# newbie" <rs****@otxresearch.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi Guys,

I know XPath is a good method to search into an xml file but what if you're looking for a specifc data which could be any where within the xml file ? Should I consider all possibilities and paths in the xml file ?!!! Isn't better to have a recurrsive method to traverse the whole tree

instead
of passing patterns to "SelectNode" method ?

Let me know if you have experience on this.

Thanks in advace
Newbie


Nov 15 '05 #4

P: n/a
On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:

Let's say I have an xml file as below and my program should find any
thing like "#19384A" or "center" in below code. Does the
"GetElementsByTagName" works for this too ?


You could use an XPath expression like the following to achieve this:

//*[contains(text(), '#19384A') or contains(text(), 'center')]

Just pass that to SelectNodes and you should be set.

Good luck,

-Derek

Nov 15 '05 #5

P: n/a
Hi Derek,

Thanks for your response but what you said it's imposibile since
SelectNode() works for nodes not data or string embedded among nodes.

"Derek Slager" <de***@activate.net> wrote in message
news:pa****************************@activate.net.. .
On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:

Let's say I have an xml file as below and my program should find any
thing like "#19384A" or "center" in below code. Does the
"GetElementsByTagName" works for this too ?


You could use an XPath expression like the following to achieve this:

//*[contains(text(), '#19384A') or contains(text(), 'center')]

Just pass that to SelectNodes and you should be set.

Good luck,

-Derek

Nov 15 '05 #6

P: n/a
Hi again Derek,

I liked your idea but I tried it on below xml code. Please if you get a
chance try it maybe there is something that I'm doing wrong! When I ran

//*[contains(text(), 'b1') or bbb the an excpetion error coems up and
compalins about DataSet!

Any idea ?

- <AAA>

<BBB id="b1" />

<BBB id="b2" />

<BBB name="bbb" />

<BBB />

</AAA>

"Derek Slager" <de***@activate.net> wrote in message
news:pa****************************@activate.net.. .
On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:

Let's say I have an xml file as below and my program should find any
thing like "#19384A" or "center" in below code. Does the
"GetElementsByTagName" works for this too ?


You could use an XPath expression like the following to achieve this:

//*[contains(text(), '#19384A') or contains(text(), 'center')]

Just pass that to SelectNodes and you should be set.

Good luck,

-Derek

Nov 15 '05 #7

P: n/a
Derek,
I have to appreciate you what you said led me to a good solution. Only some
changes to your query
thanks I appreciate it really.


"Derek Slager" <de***@activate.net> wrote in message
news:pa****************************@activate.net.. .
On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:

Let's say I have an xml file as below and my program should find any
thing like "#19384A" or "center" in below code. Does the
"GetElementsByTagName" works for this too ?


You could use an XPath expression like the following to achieve this:

//*[contains(text(), '#19384A') or contains(text(), 'center')]

Just pass that to SelectNodes and you should be set.

Good luck,

-Derek

Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.