?
Solved

how to convert a string to xml in perl

Posted on 2008-10-16
2
Medium Priority
?
1,092 Views
Last Modified: 2012-05-05
Can someone tell me how to convert a string to xml in perl ?
0
Comment
Question by:Anu2117
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 22736442
That depends on how you want the XML formatted.  

If $string contains the string, one way might be:
my $xml = "<xml>$string</xml>";

Another might be:
my $xml = "<xml string=\"$string\"></xml>";
0
 
LVL 13

Accepted Solution

by:
kawas earned 1500 total points
ID: 22817879
I prefer to use LibXML (http://search.cpan.org/~pajas/XML-LibXML/)

use XML::LibXML;
my $parser = XML::LibXML->new();
  
my $doc = $parser->parse_string($some_xml_string);
# here we get the formatted string
my $formatted_xml = $doc->toString(1);

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question