Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1168
  • Last Modified:

how to convert a string to xml in perl

Can someone tell me how to convert a string to xml in perl ?
0
Anu2117
Asked:
Anu2117
1 Solution
 
Adam314Commented:
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
 
kawasCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now