in reply to Re: XML::Compile template initialized from XML document
in thread XML::Compile template initialized from XML document
I accept the possibility. I'm new to both library families (XML::Compile and XML::LibXML) and they are large and complicated. Let me show you the code I use to compile the schema and to parse the XML that produces a structure I find difficult to use, and maybe you can help me get to this easier model
I'm trying to post the minimal helpful code. The getSASchema subroutine successfully downloads the XSD and compiles it. The saQuery subroutine successfully pulls the XML I want and runs the reader I get from the schema object's "compile" method. As you see the subroutine returns the reference that comes back from calling the reader with the XML text.
... ... sub getSASchema { my ($config, $lwp) = @_; my $saSchemaUrl = "https://" . $config->{saserver} . ":" . $config +->{saport} . "/serverautomation/SA-REST.xsd"; my $sareq = HTTP::Request->new( GET => $saSchemaUrl ); $sareq->authorization_basic($config->{besuser}, $config->{bespassw +ord}); my $xsd = $lwp->request($sareq); my $schema = XML::Compile::Schema->new($xsd->{_content}); return $schema; } ## Handle querying the Server Automation API. sub saQuery { my ($config, $lwp, $schema) = @_; my $saPlanUrl = "https://" . $config->{saserver} . ":" . $config->{saport} . "/serverautomation" . $config->{saplanurl}; my $sareq = HTTP::Request->new( GET => $saPlanUrl ); $sareq->authorization_basic($config->{besuser}, $config->{bespassw +ord}); my $xml = $lwp->request($sareq); my $planreader = $schema->compile( READER => "{http://iemfsa.tivol +i.ibm.com/REST}sa-rest"); my $xmltxt = $xml->{_content}; my $tree = $planreader->($xmltxt); return $tree; } ... ... # Down in my main. $config is a hash containing config # data parsed from a file, and $lwp is an instance of # LWP::UserAgent my $saSchema = getSASchema($config, $lwp); ## Fetch the "raw" automation plan from the BigFix SA server my $doc = saQuery($config, $lwp, $saSchema); my $basenode = $doc->{_}; print Dumper($doc); print Dumper($basenode);
As you see in my main code, I then use Dumper to see what I get from that process. Here's what I get:
$VAR1 = { '_MIXED_ELEMENT_MODE' => 'ATTRIBUTES', '_' => bless( do{\(my $o = 85686224)}, 'XML::LibXML::Element +' ) }; $VAR1 = bless( do{\(my $o = 85686224)}, 'XML::LibXML::Element' );
That is not a hash of hashes. It is XML::LibXML objects. This is how the XML::Compile documentation tells me to make a reader, but I'm not sure this reader is the same reader you refer to as XML::Compile::Translate::Reader. Maybe you can show me a fragment to replace my reader in saQuery with one that you think will produce what I want? And please remember that after modifying my structure I need to be able to use my XML::Compile::Schema object to construct compliant output XML...
I really appreciate your help. I'm learning a lot.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: XML::Compile template initialized from XML document
by markov (Scribe) on May 12, 2016 at 07:08 UTC | |
by tdane (Acolyte) on May 12, 2016 at 15:07 UTC | |
by tdane (Acolyte) on May 12, 2016 at 19:24 UTC | |
by tdane (Acolyte) on May 12, 2016 at 21:08 UTC | |
by markov (Scribe) on May 12, 2016 at 23:12 UTC |