Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: XPath to XML

by LanX (Chancellor)
on May 17, 2013 at 16:55 UTC ( #1033992=note: print w/replies, xml ) Need Help??


in reply to XPath to XML

Hi tosaiju

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

Like showing desired input & output?

edit

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)

Replies are listed 'Best First'.
Re^2: XPath to XML
by tosaiju (Acolyte) on May 20, 2013 at 07:25 UTC
    Thanks LanX for the update.

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

    /bookstore/book@category='COOKING'
    /bookstore/book/title
    /bookstore/book/title@lang='en'
    /bookstore/book/author
    /bookstore/book/year
    /bookstore/book/price
    Any chance of getting an XML file like below,

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

    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.

    Thanks,

Re^2: XPath to XML
by tosaiju (Acolyte) on May 20, 2013 at 07:51 UTC
    something like as mentioned in below site
    http://translet.sourceforge.net/
    but this is in Java and the usage looks simple

      Well, that usage is much simpler than what you posted but hey, if http://translet.sourceforge.net/ 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 :)

        That looks good. Let me play with this now.
        Thanks a lot.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033992]
help
Chatterbox?
[Discipulus]: new $workstation is arrived: SSD 250, sata 1TB, 16G RAM, only i5 CPU.. seems a good one: guess what first user installation will be?
[Corion]: Discipulus: Notepad++, or Perl ;)
[marto]: xubuntu or lubuntu
[Corion]: :-D
[marto]: my desktop is a core2 duo, 120GB SSD, 4GB RAM, boots to (GUI) login in less than 10 seconds from cold start
[Discipulus]: mah, winbuntu 10...
[marto]: whent he boys start school I'll build myself as new machine, ryzen based
[Corion]: marto: That's cool! I think my (home) desktop spends 30 seconds in the BIOS...
[Corion]: marto: Heh - currently they seem promising, but I think I'll stay with nVidia+Intel for the time being, as I've been bitten too often by bad AMD drivers

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-07-27 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (407 votes). Check out past polls.