473,399 Members | 2,159 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,399 software developers and data experts.

Problem with parsing XML file

So I'm working on a program where I need to parse multiple XML files and return their attributes in a readable format. Currently the script parses all of the files and stores all the details for each file at each position of an array. An example of the desired output for each line would be:

J MIG-49 at location "85,20,0.1" is moving to "0.5,-0.5,-300"

Below is the XML code for reference.

Expand|Select|Wrap|Line Numbers
  1. <?xml version='1.0'?>
  2. <threat>
  3.         <location>"85,20,0.1"</location>
  4.         <ftype>J</ftype>
  5.         <fmodel>MIG-49</fmodel>
  6.         <movement_speed>"0.5,-0.5,-300"</movement_speed>
  7. </threat>
And here is my current Perl script.

Expand|Select|Wrap|Line Numbers
  1. my $count=0;
  2. opendir (DIR, "../folder") or die "$!";
  3. my @feeds = grep {/threats.*?\.xml/}  readdir DIR;
  4. close DIR;
  5. # The above 3 lines read in the XML files and store them in array feeds.
  6. for $threats(@feeds) {
  7.    open (READ, $threats)||die"$!";
  8.    flock(READ, 1) || die "Can't lock xml: $!";
  9.    while (<READ>) {
  10.       $all[$count].=$_
  11.    }
  12.    close READ;
  13.    $count++;
  14. }
  15. print @all; # report
As stated previously, I need to parse out the fields for each file as I'll need them later. I'm not quite sure how to do this though as I'm relatively new to Perl. Any help would be great.
Apr 11 '12 #1
1 1672

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

Similar topics

9
by: vKp | last post by:
I'm having a problem with file(). If I try to open a url of the form "http://example.com/find?one,two", I get an error of the following form: ....failed to create stream: Bad file descriptor... ...
3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
0
by: XspiriX | last post by:
Hi I am new here and so in python :-) I am trying to make a script for extracting (parsing?) some values from a file and write them into an output i thought to follow this example (cookbook): ...
5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
0
by: Jonathan | last post by:
I have written a SAX parser to read a simple XML file using this code : SAXParserFactory factory = SAXParserFactory.newInstance(); javax.xml.parsers.SAXParser saxParser =...
6
by: Ulrich Vollenbruch | last post by:
Hi all! since I'am used to work with matlab for a long time and now have to work with c/c++, I have again some problems with the usage of strings, pointers and arrays. So please excuse my basic...
0
by: Uncle Leo | last post by:
I created an OleDbDataAdapter with the wizard in Visual Studio 2003. It created a dataset, connectionstring etc. for me to work with. It also created a .xsd file where one of the columns type is...
5
by: barronmo | last post by:
I'm having difficulty getting the following code to work. All I want to do is remove the '0:00:00' from the end of each line. Here is part of the original file: 3,3,"Dyspepsia NOS",9/12/2003...
12
by: pindoriya1 | last post by:
Hi, m using split function to parse the csv file ..... i m getting problem in one line of file which looks like this : "BLUEUSBXM","X-MICRO (XBT-DG5R (C) R1) BLUETOOTH USB DONGLE PLUS, CLASS...
2
by: ashmir.d | last post by:
Hi, I am trying to parse an xml file using the minidom parser. <code> from xml.dom import minidom xmlfilename = "sample.xml" xmldoc = minidom.parse(xmlfilename) </code> The parser is...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.