473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Searching through XML document

Hi,

I am fairly new to XML, any help is appreciated.

I would like to add a search box on my site, that will allow me to
search through NAME of the xml-list like the one below, and display a
user with their information. Name can be entered as firstname, lastname
or both.

<EMPLOYEE_LIST>
<EMPLOYEE>
<NAME>Kevin A Freeman</NAME>
<DOB>08/23/68</DOB>
<HIRE>07/01/97</HIRE>
<PIC>images/KevinFreeman.jpg</PIC>
<POSITION>Sales Manager</POSITION>
</EMPLOYEE>
<EMPLOYEE>
<NAME>Cindy Onkalavia</NAME>
<DOB>09/16/74</DOB>
<HIRE>07/01/97</HIRE>
<PIC>images/CindyOnkalavia.jpg</PIC>
<POSITION>Auditor</POSITION>
</EMPLOYEE>
Sep 8 '05 #1
3 1245
Ri*****@gmail.com wrote:
I would like to add a search box on my site, that will allow me to
search through NAME of the xml-list like the one below,


Use a database instead - this is what they _do_.

You _could_ build this with XML. But you can't just grab a pre-existing
example, as you could with a SQL database. So for "simple" cases, it's
more work.

XML is also _NOT_ a searchable format for storing huge quantities of
data (at least not through the DOM/XPath route, which is what you'll be
using if you build simpel XML sites with simple XML tool (i.e. free
stuff that works in PHP)). XML whole-document searches are horribly
slow. So if this is a big list, then it's a poor performing search.

One day we'll use XML databases with XQuery, just as we currently use
simple cheap SQL tools like MySQL - This might already have happened.
But these will be storing their searchable indices in some internal
non-XML format and limiting the XML format you show here to data
loading at most.

Sep 8 '05 #2
This XQuery primer goes through an example quite similar to what you
have posted (searching through contacts by name). Hope this helps.
http://www.stylusstudio.com/xquery_primer.html

Sincerely,
The Stylus Studio Team
http://www.stylusstudio.com

Sep 8 '05 #3
Ri*****@gmail.com wrote:
Hi,

I am fairly new to XML, any help is appreciated.

I would like to add a search box on my site, that will allow me to
search through NAME of the xml-list like the one below, and display a
user with their information. Name can be entered as firstname, lastname
or both.

<EMPLOYEE_LIST>
<EMPLOYEE>
<NAME>Kevin A Freeman</NAME>
<DOB>08/23/68</DOB>
<HIRE>07/01/97</HIRE>
<PIC>images/KevinFreeman.jpg</PIC>
<POSITION>Sales Manager</POSITION>
</EMPLOYEE>
<EMPLOYEE>
<NAME>Cindy Onkalavia</NAME>
<DOB>09/16/74</DOB>
<HIRE>07/01/97</HIRE>
<PIC>images/CindyOnkalavia.jpg</PIC>
<POSITION>Auditor</POSITION>
</EMPLOYEE>
.
.
<EMPLOYEE>
<NAME>Kevin Lee</NAME>
<DOB>03/25/81</DOB>
<HIRE>01/13/05</HIRE>
<PIC>images/KevinLee.jpg</PIC>
<POSITION>MIT</POSITION>
</EMPLOYEE>
</EMPLOYEE_LIST>


Text file, SQL, anything is better than XML. But, since you're stuck
with XML format, you might try something like

1. awk -v RS='</?EMPLOYEE>' "/Kevin/" file.xml

2. csplit file.xml '/<EMPLOYEE>/' '{*}'
for i in xx*; do
grep -q "Kevin" $i && cat $i
done

3. Use shell interface to Expat XML parser,

start()
{
case $1 in
EMPLOYEE) unset name dob hire pic position ;;
esac
}
data()
{
tag=${XML_TAG_STACK[0]}
case $tag in
NAME|DOB|HIRE|PIC|POSITION) strcat $tag $1 ;;
esac
}
end()
{
case $1 in
EMPLOYEE)
if [[ $NAME == *Kevin* ]]; then
cat <<+ EOF
NAME=$NAME
DOB=$DOB
HIRE=$HIRE
PIC=$PIC
POSITION=$POSITION
EOF
fi
;;
esac
}
expat -s start -d data -e end < file.xml

--
William Park <op**********@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
Sep 8 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
3
by: sal achhala | last post by:
I'm working with java and XML documents in order to search for keywords in a given element name, eg element name 'author' == "jo blogs". The problem is the XML documents are downloaded (this...
0
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
14
by: Ludwig77 | last post by:
I read that there are some tags that can be entered in a web page's meta tags in order to prevent web bot searching and indexing of the web page for search engines. What is the tagging that I...
2
by: Jim Kitterman | last post by:
I am looking for the most efficient way of searching a large xml document (> 14mg). If I could get some pointers in the right direction. I am using VB.NET. It is readonly.
5
by: jayjay | last post by:
I'm trying to help a friend setup a database to track resumes. The candidates will submit their resume in a Word doc format, and I'd like to make a search that will do a context search of the...
1
by: Darrel | last post by:
Can anyone recommend a product/technique/component that would be capable of indexing PDF and MSWord document's and then searching against them? I've used index serviices for things like this in...
3
by: Steven Munlo | last post by:
Hi, I'm searching for a document managing system for several users. I want to save Word-DOCs and Adobe-PDFs and do full text searches on them? Also, it should be an open source project. Does...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.