XML Search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C# newbie

    XML Search

    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

    #2
    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@otxrese arch.com> wrote in message
    news:#$AvUhz#DH A.1452@TK2MSFTN GP09.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]


    Comment

    • Richard T. Edwards@pwpsquared.net

      #3
      Re: XML Search

      GetElementsByTa gName is one way to do it.


      "C# newbie" <rsavra@otxrese arch.com> wrote in message
      news:%23$AvUhz% 23DHA.1452@TK2M SFTNGP09.phx.gb l...[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]


      Comment

      • C# newbie

        #4
        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 "GetElementsByT agName" works for this too ?

        <?xml version="1.0"?>
        <Form SurveyName="emp ty" SurveyID="1" StyleUsage="URL "
        xmlns=http://www.yahoo.com SurveyProgramme r="ramsin" DateTime="2/12/2004
        5:00:54 PM">
        <Params>
        <BackgroundColo r>#19384A</BackgroundColor >
        <LinkColor>#fff fff</LinkColor>
        <VisitedLinkCol or>#ffffff</VisitedLinkColo r>
        <TextColor>#fff fff</TextColor>
        <Direction>lt r</Direction>
        <BackgroundImag e>
        </BackgroundImage >
        <Header>&lt;tab le width='600' cellspacing='0' callpadding='0' border='0'
        align='center'& gt;
        </Params>
        ....
        .....
        ......
        ......
        ......
        </Form>

        Thanks



        "Richard T. Edwards@pwpsqua red.net" <redwar@pwpsqua red.net> wrote in message
        news:%23mqmr%23 z%23DHA.2484@TK 2MSFTNGP12.phx. gbl...[color=blue]
        > GetElementsByTa gName is one way to do it.
        >
        >
        > "C# newbie" <rsavra@otxrese arch.com> wrote in message
        > news:%23$AvUhz% 23DHA.1452@TK2M SFTNGP09.phx.gb l...[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]


        Comment

        • Derek Slager

          #5
          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
          > "GetElementsByT agName" 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

          Comment

          • C# newbie

            #6
            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.0 2.25.03.34.05.6 49109@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
            > > "GetElementsByT agName" 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]


            Comment

            • C# newbie

              #7
              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.0 2.25.03.34.05.6 49109@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
              > > "GetElementsByT agName" 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]


              Comment

              • C# newbie

                #8
                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.0 2.25.03.34.05.6 49109@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
                > > "GetElementsByT agName" 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]


                Comment

                Working...