Search through XML file

Last post 07-03-2008 11:56 AM by Nike1984. 4 replies.

Sort Posts:

  • Search through XML file

    07-03-2008, 10:38 AM
    • Loading...
    • Nike1984
    • Joined on 04-22-2008, 2:04 PM
    • Posts 22

     A bit stuck here, and just can't get started on a project.

    I basically want to offer a search function through an XML file.

    I have a sample file let's say a list of hotels

     

    <hotels>
     <hotel>
      <id>1</id>
      <name>Sheraton</name>
      <address>11 Test st</address>
      <city>New York</city>
      <state>NY</state>
     </hotel>
    
     <hotel>
      <id>1</id>
      <name>Marriott</name>
      <address>11 Test st</address>
      <city>New York</city>
      <state>NY</state>
     </hotel>
    
     <hotel>
      <id>1</id>
      <name>Sheraton</name>
      <address>11 Test st</address>
      <city>Los Angeles</city>
      <state>CA</state>
     </hotel>
    <hotels>

      

    I want to be able to query XML file and retrieve the list of hotels in, let's say New York and then manipulate the data for display....  Any ideas where I can start? 

    Also, as a side question - my original XML file is quiet large and as I understand it might deliver a slow performance. It contains a little over 100k records. Is there a way to make it a little more efficient? Or will it not be a big issue? 

    Any help would be appreciated.

    Thank you,
    Nick

  • Re: Search through XML file

    07-03-2008, 11:01 AM
    Answer

     You can use XPATH. For example to find New York:

     

    //city[. = 'New York']

     

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: Search through XML file

    07-03-2008, 11:12 AM
    • Loading...
    • Nike1984
    • Joined on 04-22-2008, 2:04 PM
    • Posts 22

     Yeah, that's what I came across as well.

    Any sample code?  This will be helpful.

    Thank you,

    Nick

  • Re: Search through XML file

    07-03-2008, 11:39 AM

     I have to dig through my snippets. I use XSLT and pass the search parameter to the stylesheet. I will try to find it.

     

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: Search through XML file

    07-03-2008, 11:56 AM
    • Loading...
    • Nike1984
    • Joined on 04-22-2008, 2:04 PM
    • Posts 22

     THank you Bonekrusher

    Nick

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter