Connecting Tech Pros Worldwide Forums | Help | Site Map

XML Search

C# newbie
Guest
 
Posts: n/a
#1: Nov 15 '05
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



Bob Boran
Guest
 
Posts: n/a
#2: Nov 15 '05

re: XML Search


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" <rsavra@otxresearch.com> wrote in message
news:#$AvUhz#DHA.1452@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
instead[color=blue]
> of passing patterns to "SelectNode" method ?
>
> Let me know if you have experience on this.
>
> Thanks in advace
> Newbie
>
>[/color]


Richard T. Edwards@pwpsquared.net
Guest
 
Posts: n/a
#3: Nov 15 '05

re: XML Search


GetElementsByTagName is one way to do it.


"C# newbie" <rsavra@otxresearch.com> wrote in message
news:%23$AvUhz%23DHA.1452@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
instead[color=blue]
> of passing patterns to "SelectNode" method ?
>
> Let me know if you have experience on this.
>
> Thanks in advace
> Newbie
>
>[/color]


C# newbie
Guest
 
Posts: n/a
#4: Nov 15 '05

re: XML Search



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. Edwards@pwpsquared.net" <redwar@pwpsquared.net> wrote in message
news:%23mqmr%23z%23DHA.2484@TK2MSFTNGP12.phx.gbl.. .[color=blue]
> GetElementsByTagName is one way to do it.
>
>
> "C# newbie" <rsavra@otxresearch.com> wrote in message
> news:%23$AvUhz%23DHA.1452@TK2MSFTNGP09.phx.gbl...[color=green]
> > Hi Guys,
> >
> > I know XPath is a good method to search into an xml file but what[/color][/color]
if[color=blue][color=green]
> > you're looking for a specifc data which could be any where within the[/color][/color]
xml[color=blue][color=green]
> > file ? Should I consider all possibilities and paths in the xml file[/color][/color]
?!!![color=blue][color=green]
> > Isn't better to have a recurrsive method to traverse the whole tree[/color]
> instead[color=green]
> > of passing patterns to "SelectNode" method ?
> >
> > Let me know if you have experience on this.
> >
> > Thanks in advace
> > Newbie
> >
> >[/color]
>
>[/color]


Derek Slager
Guest
 
Posts: n/a
#5: Nov 15 '05

re: XML Search


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

[color=blue]
> 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 ?[/color]

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

C# newbie
Guest
 
Posts: n/a
#6: Nov 15 '05

re: XML Search


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" <derek@activate.net> wrote in message
news:pan.2004.02.25.03.34.05.649109@activate.net.. .[color=blue]
> On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:
>
>[color=green]
> > 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 ?[/color]
>
> 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
>[/color]


C# newbie
Guest
 
Posts: n/a
#7: Nov 15 '05

re: XML Search


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" <derek@activate.net> wrote in message
news:pan.2004.02.25.03.34.05.649109@activate.net.. .[color=blue]
> On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:
>
>[color=green]
> > 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 ?[/color]
>
> 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
>[/color]


C# newbie
Guest
 
Posts: n/a
#8: Nov 15 '05

re: XML Search


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" <derek@activate.net> wrote in message
news:pan.2004.02.25.03.34.05.649109@activate.net.. .[color=blue]
> On Tue, 24 Feb 2004 18:35:58 -0800, C# newbie wrote:
>
>[color=green]
> > 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 ?[/color]
>
> 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
>[/color]


Closed Thread


Similar C# / C Sharp bytes