Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Parsing Data from XML Schemas

by meetraz (Hermit)
on Jun 16, 2004 at 00:20 UTC ( [id://367089]=note: print w/replies, xml ) Need Help??


in reply to Parsing Data from XML Schemas

Do you really mean an XML schema (.xsd) document, or just plain XML data? If it's coming from a SQL query, it's probably just XML data and XML::Simple (for small XML files) or XML::Parser (for large ones) would probably work ok.

Replies are listed 'Best First'.
Re^2: Parsing Data from XML Schemas
by mosiondz (Acolyte) on Jun 16, 2004 at 16:21 UTC

    As far as I understand it, the script returns an XML Schema (I might be off on the terminology here). It starts off with the following:

    - <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="u +uid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-micro +soft-com:rowset" xmlns:z="#RowsetSchema"> - <s:Schema id="RowsetSchema">
    Would I be correct in calling this a schema?
      In this case, it's an XML file with the database schema and rowset data embedded within it. If you look at the XML file, it should have <s:Schema> and <rs:data> sections.

      Try something like this.. I've tested it and it works. Note that XML::Simple reads the entire XML file into memory and therefore is not ideal for large datasets.

      use strict; use XML::Simple; my $xs = XML::Simple->new(); my $sqlref = $xs->XMLin('sqldata.xml'); my $rowsref = $sqlref->{'rs:data'}{'z:row'}; foreach my $row (@$rowsref) { print "---------New Row--------\n"; print $row->{'column1'}, "\n"; print $row->{'column2'}, "\n"; print $row->{'column3'}, "\n"; }

        Thanks for the code example, meetraz! However, I receive "Not an ARRAY reference" on the following line:

        foreach my $row (@$rowsref) {

        I'm not sure why I'd be receiving this error, as everything seems to assigned correctly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://367089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found