#1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,337
    Rep Power
    594

    Using XML::LibXML with existing XML object


    I inadvertently posted a similar thread (using XML::XPath) in the PHP forum which has not yet been moved but since I've decided to switch to XML::LibXML, I'll re-ask it here.

    I have a method that returns an XML object. Now I want to use XML:LibXML to find nodes containing certain values. My first obstacle is figuring out how to get an XML::LibXML object from an existing XML::Simple object. All the examples show how to get it using a file or string. Do I really have to convert the existing XML object back to XML then feed that to XML::LibXML->new?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    I think the best approach would be to drop XML::Simple and do everything with XML::LibXML.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,337
    Rep Power
    594
    The module I'm using in my script returns an XML object. I can't change that.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    If your returned XML::Simple object is $xml, then you could pass it (i.e., the xml, not the object) to XML:LibXML like this (untested).

    Code:
    my $dom = XML::LibXML->load_xml( string => XMLout($xml) );
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,337
    Rep Power
    594
    Thanks. Converting an XML object into a string, then back to an XML object seemed inefficient. I thought there was a better way to insert it directly. I kind of thought I was going to have to go through a double conversion but was hoping otherwise.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo