Search a string inside an xml node
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > IIS server support > IIS ASP > Search a string inside an xml node




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Search a string inside an xml node  
lejason@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-20-07 06:20 PM

Hello, I am looking for a way to do a string search inside an xml.
Basically, I work for a company that wants to export an XML file from
and excel sheet and then have that data be presented on the web.  Part
of the presentation is that they want to be able to "search" for their
favorite dealers.  So, this will be a string search.

The difficulty is, we dont have .NET, we dont have a SQL server -- all
I can use is ASP classic.

So, I can read/parse the XML and I can search for static things like
zip codes and products (products from a drop down list that dont
change) using simple "if" statements however, when it comes to a
string, unless the user enters it EXACTLY how its spelled an
punctuated in the XML, it wont return the match (of course).

I've read about a lot of functionality that .NET offers for string
search, but I havent yet found anything for classic.

The code I am going to post works and will eventually become the
actual engine, but for now the variables are for people - name, color,
number.

So the million dollar question is, if I wanted to add another
dimension to my array that had a string where I wanted to pick up on
keywords - lets say one word in up to 230 characters, how on earth
would I create a function to make it searchable (search inside of a
string)

thanks guys

(here is the code)

<%

Dim xdoc
Set xdoc=Server.CreateObject("Microsoft.XMLDOM")
xdoc.async=false
xdoc.load("/newtext.xml")

if xdoc.parseError.errorcode<>0 then
response.write "there was obviously an error"
else
response.write "Things worked"
end if

dim theLength
theLength = xdoc.SelectNodes("/test/person").length

dim counter
counter = 0

dim theArray()
ReDim theArray(theLength, 2)

For Each elemPerson in xdoc.SelectNodes("/test/person")
For Each elem in elemPerson.SelectNodes("*")
theArray(counter,0)= elemPerson.childNodes(0).text
theArray(counter,1)= elemPerson.childNodes(1).text
theArray(counter,2)= elemPerson.childNodes(2).text
Next
counter = counter + 1
Next

dim real
real = theLength - 1

dim rowcounter
rowcounter = 1

For i=0 to real

dim personName
personName = theArray(i, 0)
dim personColor
personColor = theArray(i, 1)
dim personNumber
personNumber = theArray(i, 2)


dim search_name
search_name = "Jason"
dim search_color
search_color = "blue"
dim search_number
search_number = "16"


dim color
color = " class='even'"

if rowcounter MOD 2 <> 0 then
color = " class='odd'"
end if

if (personName = search_name or personColor = search_color) then
response.write "<tr" & color &">"
response.write "<td>" & personName & "</td>"
response.write "<td>" & personColor & "</td>"
response.write "<td>" & personNumber & "</td>"
response.write "<td>" & rowcounter & "</td>"
response.write "</tr>"

rowcounter = rowcounter + 1

end if

Next

%>






[ Post a follow-up to this message ]



    Re: Search a string inside an xml node  
Jon Paal [MSMD]


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-21-07 12:19 AM

this may help


http://www.1aspstreet.com/vb/script...d=6367&lngWId=4



<lejason@gmail.com> wrote in message news:1174410728.352117.201070@l77g2000hsb.googlegroups.
com...
> Hello, I am looking for a way to do a string search inside an xml.
> Basically, I work for a company that wants to export an XML file from
> and excel sheet and then have that data be presented on the web.  Part
> of the presentation is that they want to be able to "search" for their
> favorite dealers.  So, this will be a string search.
>
> The difficulty is, we dont have .NET, we dont have a SQL server -- all
> I can use is ASP classic.
>
> So, I can read/parse the XML and I can search for static things like
> zip codes and products (products from a drop down list that dont
> change) using simple "if" statements however, when it comes to a
> string, unless the user enters it EXACTLY how its spelled an
> punctuated in the XML, it wont return the match (of course).
>
> I've read about a lot of functionality that .NET offers for string
> search, but I havent yet found anything for classic.
>
> The code I am going to post works and will eventually become the
> actual engine, but for now the variables are for people - name, color,
> number.
>
> So the million dollar question is, if I wanted to add another
> dimension to my array that had a string where I wanted to pick up on
> keywords - lets say one word in up to 230 characters, how on earth
> would I create a function to make it searchable (search inside of a
> string)
>
> thanks guys
>
> (here is the code)
>
> <%
>
> Dim xdoc
> Set xdoc=Server.CreateObject("Microsoft.XMLDOM")
> xdoc.async=false
> xdoc.load("/newtext.xml")
>
> if xdoc.parseError.errorcode<>0 then
> response.write "there was obviously an error"
> else
> response.write "Things worked"
> end if
>
> dim theLength
> theLength = xdoc.SelectNodes("/test/person").length
>
> dim counter
> counter = 0
>
> dim theArray()
> ReDim theArray(theLength, 2)
>
> For Each elemPerson in xdoc.SelectNodes("/test/person")
> For Each elem in elemPerson.SelectNodes("*")
> theArray(counter,0)= elemPerson.childNodes(0).text
> theArray(counter,1)= elemPerson.childNodes(1).text
> theArray(counter,2)= elemPerson.childNodes(2).text
> Next
> counter = counter + 1
> Next
>
> dim real
> real = theLength - 1
>
> dim rowcounter
> rowcounter = 1
>
> For i=0 to real
>
> dim personName
> personName = theArray(i, 0)
> dim personColor
> personColor = theArray(i, 1)
> dim personNumber
> personNumber = theArray(i, 2)
>
>
> dim search_name
> search_name = "Jason"
> dim search_color
> search_color = "blue"
> dim search_number
> search_number = "16"
>
>
> dim color
> color = " class='even'"
>
> if rowcounter MOD 2 <> 0 then
> color = " class='odd'"
> end if
>
> if (personName = search_name or personColor = search_color) then
> response.write "<tr" & color &">"
> response.write "<td>" & personName & "</td>"
> response.write "<td>" & personColor & "</td>"
> response.write "<td>" & personNumber & "</td>"
> response.write "<td>" & rowcounter & "</td>"
> response.write "</tr>"
>
> rowcounter = rowcounter + 1
>
> end if
>
> Next
>
> %>
>







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:13 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register