Solved

how to convert a string to xml in perl

Posted on 2008-10-16
2
1,005 Views
Last Modified: 2012-05-05
Can someone tell me how to convert a string to xml in perl ?
0
Comment
Question by:Anu2117
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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now