Hi ,
The xml file is generated as a webpage. The XML file is just 10 lines. The XML file will be like this : - <ABC>
-
<D someattribute="">
-
<EF baseRef="http://.............." id="some id value" />
-
</D>
-
<D someattribute="">
-
<EF baseRef="http://.............." id="some id value" />
-
</D>
-
</ABC>
All i want to extract from this xml file is list of "id" in perl..
I tried doing like this : - #!/usr/local/bin/perl
-
my $xml_file = 'http://www.w3.org/TR/2001/REC-xsl-20011015/xslspec.xml';
-
my @hosts;
-
-
open(my $XMLFILE, '<', $xml_file) ||die "Can't open file: $!";
-
-
while(my $line=<$XMLFILE>)
-
{
-
if($line =~ /<head>(.*)<\/head>/)
-
{
-
push @hosts,$l;
-
}
-
}
-
close($XMLFILE);
-
print join (",",@hosts);
The error i got are :
Name "main::l" used only once: possible typo at host1.cgi line 11.
Can't open file: No such file or directory at host1.cgi line 5.
Can you suggest me the easiest way to get a string from an XML file(not present in my system , but available as a webpage in our company )
9 1605 eWish 971
Recognized Expert Contributor
Welcome to TSDN!
Please do not double post your questions. I have deleted your other post for you. Also, when posting code please use the [CODE][/CODE] tags.
Thank You,
Kevin
eWish 971
Recognized Expert Contributor
To help debug you can add the following pragmas which is considered good practice. - use strict;
-
use warnings;
You can just rewrite the regex to look for the id and capture what is between the " " only. - if($line =~ /id="(.*)"/) {
There may be some speeding penalties.
--Kevin
Hi ,
The xml file is generated as a webpage. The XML file is just 10 lines. The XML file will be like this : - <ABC>
-
<D someattribute="">
-
<EF baseRef="http://.............." id="some id value" />
-
</D>
-
<D someattribute="">
-
<EF baseRef="http://.............." id="some id value" />
-
</D>
-
</ABC>
All i want to extract from this xml file is list of "id" in perl..
I tried doing like this : - #!/usr/local/bin/perl
-
my $xml_file = 'http://www.w3.org/TR/2001/REC-xsl-20011015/xslspec.xml';
-
my @hosts;
-
-
open(my $XMLFILE, '<', $xml_file) ||die "Can't open file: $!";
-
-
while(my $line=<$XMLFILE>)
-
{
-
if($line =~ /<head>(.*)<\/head>/)
-
{
-
push @hosts,$l;
-
}
-
}
-
close($XMLFILE);
-
print join (",",@hosts);
The error i got are :
Name "main::l" used only once: possible typo at host1.cgi line 11.
Can't open file: No such file or directory at host1.cgi line 5.
Can you suggest me the easiest way to get a string from an XML file(not present in my system , but available as a webpage in our company )
Thanks a lot for your reply.
Now the above code is returning the entire line that is matched.
EX: - <EF baseRef="http://.............." id="HOST1" />
-
<GH baseRef="http://.............." id="HOST2" />
-
<IJ baseRef="http://.............." id="HOST3" />
-
All I want now is HOST1,HOST2,HOS T3 seperated with single comma as a single string.
How do i get only HOST1 rather than complete line
<EF baseRef="http://.............." id="HOST1" />
Please help me.
Thanks in Advance
KevinADC 4,059
Recognized Expert Specialist - if($line =~ /id="(.*)"/) {
-
push @hosts,$1;
-
}
-
print "$_\n" for @hosts;
- if($line =~ /id="(.*)"/) {
-
push @hosts,$1;
-
}
-
print "$_\n" for @hosts;
It Worked, Hurrayyyyyyyyyy yyyyyyyyyyyyy..
Thanks much much much...
Thanks a lot Kevin.. You are an Expert. Thank youuuuuuuuuu
It Worked, Hurrayyyyyyyyyy yyyyyyyyyyyyy..
Thanks much much much...
Thanks a lot Kevin.. You are an Expert. Thank youuuuuuuuuu
Sorry to trouble you again,
My Present Code is : -
#!/usr/bin/perl
-
use strict;
-
use warnings;
-
my $xml_file = 'c.xml';
-
my @hosts;
-
-
open(my $XMLFILE, '<', $xml_file) ||die "Can't open file: $!";
-
while(my $line=<$XMLFILE>)
-
{
-
if($line =~ /id="(.*)"/)
-
{
-
push @hosts,$1;
-
}
-
}
-
print "$_\n" for @hosts;
-
close($XMLFILE);
-
-
The Above code works absolutely if i give the XML file directly.
But the URL is not directly the xml file. We need to send a GET request for it.
Now i need to send a GET Request to a URL rather than directly specifying the link as C.XML
If i use something like this : -
use LWP::Simple;
-
$content = get("URL");die "Couldn't get it!" unless defined $content;
-
-
Now this is no more a file, rather $content contains string.
How do i Apply the above code in this case.
Waiting for your reply ,
Thanks for the help so far and please help me this time too.
-Alex.
Sorry to trouble you again,
My Present Code is : -
#!/usr/bin/perl
-
use strict;
-
use warnings;
-
my $xml_file = 'c.xml';
-
my @hosts;
-
-
open(my $XMLFILE, '<', $xml_file) ||die "Can't open file: $!";
-
while(my $line=<$XMLFILE>)
-
{
-
if($line =~ /id="(.*)"/)
-
{
-
push @hosts,$1;
-
}
-
}
-
print "$_\n" for @hosts;
-
close($XMLFILE);
-
-
The Above code works absolutely if i give the XML file directly.
But the URL is not directly the xml file. We need to send a GET request for it.
Now i need to send a GET Request to a URL rather than directly specifying the link as C.XML
If i use something like this : -
use LWP::Simple;
-
$content = get("URL");die "Couldn't get it!" unless defined $content;
-
-
Now this is no more a file, rather $content contains string.
How do i Apply the above code in this case.
Waiting for your reply ,
Thanks for the help so far and please help me this time too.
-Alex.
Hi Alex,
After getting the entire data into $content, you can split it line by line and store it in an array and use the same code for this array.. - my @contents = split(/\n/,$content);
-
foreach my $line (@contents)
-
{
-
if($line =~ /id="(.*)"/)
-
{
-
push @hosts,$1;
-
}
-
}
...
Hope this helps..
Hi Alex,
After getting the entire data into $content, you can split it line by line and store it in an array and use the same code for this array.. - my @contents = split(/\n/,$content);
-
foreach my $line (@contents)
-
{
-
if($line =~ /id="(.*)"/)
-
{
-
push @hosts,$1;
-
}
-
}
...
Hope this helps..
I did so, but I am able to get everything from the first match of the regular expression ie., everything from the first id name.
The problem is when i am changing the xml into a string, everything is in a single string(i dont think that it is returning as a sequence of lines , rather it is single string i used split but then i am not sure where did it go wrong). and $1 is returning the first match, thus i am able to get the first id , and everything from there.
KevinADC 4,059
Recognized Expert Specialist
Check the LWP::Simple documentation, you can probably write the data to a file then open the file like you were doing. Not sure if it will work but you can try.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve |
last post by:
I have a web app that needs to parse through a file that is located on the
client machine. I get the file string from a query string & then parse it.
It is working fine on my development box but when I put it out on the test
server the application is looking for the file on the server & not on the
client machine.
I am essentially taking the query string & using a stream reader to read the
file.
I'm sure i'm doing something...
|
by: Prabhat |
last post by:
Hi All,
I have BIG Problem in ASP.
I have a ADO Connection that I Want to Connect to DBASE IV Database Located
in a Local Networked System.
The DBASE Database is located in other system then the IIS System in the
same Network.But Both are in the same Local Network
|
by: Andrew Edwards |
last post by:
I have program that downloads a file from the internet and extracts it using
calls to system(). All files are extracted into the directory where my
program is located. How do I redirect the extracted files to a specified
directory?
I can use the following:
system("move *.* c:\directory");
However, this will move my program. I end up having to call system for every
|
by: Dickyb |
last post by:
Extracting an Icon and Placing It On The Desktop (C# Language)
I constructed a suite of programs in C++ several years ago that handle my
financial portfolio, and now I have converted them to C#. The only
significant problem that I have encountered in the conversion is this one -
extracting an icon from the 'KTEntryPoint' program into the software suite
and placing that icon on the PC Desktop.
|
by: sunilj20 |
last post by:
Hello,
I have a requirement wherein, a user clicks on a file name in an
ASP.NET web application, and the file should automatically be
downloaded (Without showing the "Open", "Save As") in the local machine
at a pre defined path (path defined in the registry), and launch the
file in its associated application.
I think this can be done through ActiveX Controls, but i dont know how
to create ActiveX controls in .NET??
| |
by: Sohan Kamat |
last post by:
Hi,
I have a webform and I want to create a hyperlink to a text file, so that it
opens on internet explorer in a new window.
I have added the following
<a href="file:///D:/Test/Test.txt" id="hplTest" runat="server"
>testhyperlink</a>
Now when I click on the hyperlink, nothing is happening. No error.
when I open a browser and type file:///D:/Test/Test.txt, the file is opening.
|
by: Mag Gam |
last post by:
Hi All,
I am new to XML, and trying to extract some data from a file.
The file looks like this:
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
|
by: sebzzz |
last post by:
Hi,
I work at this company and we are re-building our website: http://caslt.org/.
The new website will be built by an external firm (I could do it
myself, but since I'm just the summer student worker...). Anyways, to
help them, they first asked me to copy all the text from all the pages
of the site (and there is a lot!) to word documents. I found the idea
pretty stupid since style would have to be applied from scratch anyway
since we...
|
by: =?Utf-8?B?S2VycnkgTW9vcm1hbg==?= |
last post by:
Perry,
Application.StartupPath gives you the location of the exe file. This is
where the database is assumed to be located if you don't say otherwise.
If your database is in a folder named Database that is a subfolder of the
folder where your exe file is located then you should be able to do this:
Data Source=Database\Database.mdb
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |