473,503 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ruby- need to fetch the xpath from a file

6 New Member
Hi

I am writing xpath for the components, but need to put and then fetch the same from a file. I need to name evey xpath and then put the reference to fetch from the file. Please let me know if this can be done.

Thanks in advanvce
Harry
May 14 '10 #1
2 2474
improvcornartist
303 Recognized Expert Contributor
I'm not overly familiar with xpath, so I can't really tell you how to do this, but it should be doable. You might want to look into REXML.
May 14 '10 #2
cr4sh
20 New Member
please try this-
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/ruby -w
  2.  
  3. require 'rexml/document'
  4. include REXML
  5.  
  6. xmlfile = File.new("movies.xml")
  7. xmldoc = Document.new(xmlfile)
  8.  
  9. # Info for the first movie found
  10. movie = XPath.first(xmldoc, "//movie")
  11. p movie
  12.  
  13. # Print out all the movie types
  14. XPath.each(xmldoc, "//type") { |e| puts e.text }
  15.  
  16. # Get an array of all of the movie formats.
  17. names = XPath.match(xmldoc, "//format").map {|x| x.text }
  18. p names
  19.  
this will yield the following result

<movie title='Enemy Behind'> ... </>
War, Thriller
Anime, Science Fiction
Anime, Action
Comedy
["DVD", "DVD", "DVD", "VHS"]
Jul 25 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2900
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
1
1885
by: Guanghong Xu | last post by:
Hello, Is there a sample script to get a file from a URL? Thanks.
0
1539
by: Simang | last post by:
Hi everyone, I'm an xpath newbie and needed help from all of you. I need to get all elements that do not have any children. Is there such an expression? I would need to use this for the...
1
5105
by: saiho yuen | last post by:
Hello, I'm a beginner of Javascript, I wish to know it is possbile to fetch a file (its textual or graphical content) with a http type address. Also where I can find the object, keyword,...
8
3914
by: info | last post by:
Don't any of you MVPs have a copy of this file -- msoutl.h-- it's referenced in lots of MS sample code.
7
2233
by: The Cool Giraffe | last post by:
Please note that i do intend to use a header file. However, i'm not sure if it's really needed or just a convention. Suppose we have the following two files. // Something.h class Something {...
0
943
by: itsmesrini85 | last post by:
Hi' i need a jar file "TagSys.jar". If any of you have that file, pls reply.. Thanx
2
1803
by: DDD | last post by:
I have a web site project using C#. If I release the web site in the VS2005, all works well except that DLL file name has some strange, name APP_Code_erwer234.dll. And erwer234 is a random string....
8
4839
drhowarddrfine
by: drhowarddrfine | last post by:
I have a simple VBScript that goes on the 'net, fetches a page from a specific URL, and prints it on the default printer. The problem is I need that page to print on the secondary printer. VBScript...
0
7064
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
7315
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...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
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...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.