Search code examples
perlxml-simple

Can I use XML::Simple with an in-memory string, rather than a file?


XML::Simple documentation says to initiate the data structure with an XML file, using XMLin('[FILENAME]') ... but I have an in-memory string.

Can I use it directly, or do I need to save it to the filesystem and then load it into XMLin?


Solution

  • You seem to have missed in said documentation the following information:

    XMLin() accepts an optional XML specifier followed by zero or more 'name => value' option pairs. The XML specifier can be one of the following:

    ...

    A string of XML

    A string containing XML (recognised by the presence of '<' and '>' characters) will be parsed directly. eg:

      $ref = XMLin('<opt username="bob" password="flurp" />');