CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
accessing XML string using regular expression

 



krishperl
New User

Nov 18, 2009, 1:54 AM

Post #1 of 3 (4441 views)
accessing XML string using regular expression Can't Post

/I have clubed both my postings to a single one so its more readable

query to fetch the first name,lastname,id of that particular login.

Here is the string

<?xml version="1.0"?><poc_list name="node"><poc notify="on" userType="login" includeHistory="off">fieldwatch</poc></poc_list>

The field I am trying to read is fieldwatch which is the login name in a table called user.

i need help in reg exp to read that login name and use that with a query in array to read users first_name,last_name from another table called user. ( which is accessed using DBI - mySQL)

more to add here is that the items for user table

id,last_name,first_name,role,login etc.

what ever values I get from reading the xml string eg "fieldwatch" need to be stored in array. and use that array to read all the user last_name,first_name etc from the user table.


toolic
User

Nov 18, 2009, 11:22 AM

Post #2 of 3 (4423 views)
Re: [krishperl] accessing XML string using regular expression [In reply to] Can't Post

Parsing XML is notoriously difficult. If you are open to an alternative solution, use a CPAN XML parser module, such as XML::Twig:


Code
use strict; 
use warnings;
use XML::Twig;

my $xfile = <<'EOF';
<?xml version="1.0"?><poc_list name="node"><poc notify="on" userType="login" includeHistory="off">fieldwatch</poc></poc_list>
EOF

my $t = new XML::Twig();
$t->parse($xfile);
my $plist = $t->root();
print $plist->first_child('poc')->text(), "\n";



ichi
User

Nov 19, 2009, 5:10 PM

Post #3 of 3 (4361 views)
Re: [krishperl] accessing XML string using regular expression [In reply to] Can't Post

without XML parser (not recommended for complex XML parsing)

Code
$str=q(<?xml version="1.0"?><poc_list name="node"><poc notify="on" userType="login" includeHistory="off">fieldwatch</poc></poc_list>); 
@s = split "</poc>", $str ;
$s[0] =~ s/.*>//;
print $s[0];


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives