Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

XPath to XML

by tosaiju (Acolyte)
on May 17, 2013 at 13:23 UTC ( #1033971=perlquestion: print w/ replies, xml ) Need Help??
tosaiju has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks,

Are there any modules or functionality to create a XML file from XPATH and Data?

Lets take we have a list of XPath and Data associated to this, is that possible to construct a well formed xml from this?

Thanks a lot for the help and guidence.

Kind Regards,

Comment on XPath to XML
Replies are listed 'Best First'.
Re: XPath to XML
by LanX (Chancellor) on May 17, 2013 at 16:55 UTC
    Hi tosaiju

    Could you please give us an example how this should ideally work?

    Like showing desired input & output?


    IIRC does XPath allows various wildcards on various axis to seek flexibly within the doc tree.

    Thats pretty complex or just impossible to use such incomplete information as a document definition.

    But if you don't allow wildcards your pretty close at defining how to put data into nested structures (AoH...). (something like Data::Diver comes to mind or just plain autovivification)

    So using a module which uses something like XPath to set Perl datastructures and exporting them to XML (e.g. see cpan for dump xml) could be a way to address this task.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Thanks LanX for the update.

      lets take I have an input like below and related data,

      Any chance of getting an XML file like below,

      <book category="COOKING">
      <title lang="en">Everyday Italian</title>
      <author>Giada De Laurentiis</author>

      I undersatnd Xpath generally works the otherway around and traversing XML file, but wondering any modules - which helps in constructing XML file from given XPath.


      something like as mentioned in below site
      but this is in Java and the usage looks simple

        Well, that usage is much simpler than what you posted but hey, if works use it

        I vaguely recall seeing that before, writing (tree) like that before , and my code practically already does that :P

        update: [cpan://xpath xml ] [cpan://xpath parser ] -> XML::XPathToXML - Generates XML document from XPath expressions

        See, I knew xsh had it :)

Re: XPath to XML (xpath2html)
by Anonymous Monk on May 17, 2013 at 18:42 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1033971]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-11-27 22:48 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (734 votes), past polls