Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting a string from an XML file 1

Status
Not open for further replies.

ahammad

Programmer
Sep 24, 2007
10
0
0
FR
Hello,

I have an XML file that I need to extract data from. The file has multiple lines, one of which contains the following tag:

Code:
<Owner> owner's name goes here </Owner>

I need to be able to extract the owner's name from the XML file. I have never programmed Perl before, but I have a pretty strong background in C/C++ and Java. You're probably wondering why the hell I'm jumping into this with no experience in Perl...it wasn't my choice, really. I just started working for a company and the person in charge of the Perl scripts is no longer here, and I just happened to be the only person free enough to take over the project.

I've been doing some research on regular expressions and I found this code:

Code:
if($mystring =~ m/start(.*)end/) {
	print $1;
}

Apparently, this would print everything between the word "start" and "end". Based on this, would the following code work?

Code:
if($mystring =~ m/<Owner>(.*)</Owner>/) {
	print $1;
}

I'm thinking that the / in </Owner> would cause problems...how would that be fixed?

Thanks for your help.
 
I answered your question at the other forum you posted your question on. I agree with travs69 you need an XML parser. To many possible problems rolling your own solution.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top