I have a xml file with the following schema:
<?xml version="1.0" encoding="utf-8" ?>- <xs:schema id="EverNetOffice" + targetNamespace="http://www.nwmls.com/Schemas/General/EverNetOfficeX +ML.xsd" elementFormDefault="qualified" xmlns="http://www.nwmls.com/Sc +hemas/General/EverNetOfficeXML.xsd" xmlns:mstns="http://www.nwmls.com +/Schemas/General/EverNetOfficeXML.xsd" xmlns:xs="http://www.w3.org/20 +01/XMLSchema">- <xs:element name="Office">- <xs:complexType>- <xs:sequence> <xs:element name="NRDSID" type="String11" /> <xs:element name="AssociationId" type="xs:nonNegativeInteger" /> <xs:element name="OfficeType" type="String4" /> <xs:element name="Status" type="String1" />- <xs:element name="Contact" maxOccurs="1" minOccurs="1">- <xs:complexTy +pe>- <xs:sequence> <xs:element name="Email" type="String80" /> <xs:element name="WebAddress" type="String80" /> <xs:element name="OfficeAreaCode" type="xs:nonNegativeInteger" /> <xs:element name="OfficePhone" type="xs:nonNegativeInteger" /> <xs:el +ement name="FaxAreaCode" type="xs:nonNegativeInteger" /> <xs:element name="FaxPhone" type="xs:nonNegativeInteger" /> </xs:sequ +ence> </xs:complexType> </xs:element>- <xs:element name="Address" minOccurs="1">- <xs:complexType>- <xs:sequence> <xs:element name="CareOf" type="String30" /> <xs:element name="Street" type="String30" /> <xs:element name="City" type="String21" /> <xs:element name="State" type="String2" /> <xs:element name="Zip" type="xs:nonNegativeInteger" /> <xs:element na +me="ZipPlus4" type="xs:nonNegativeInteger" /> <xs:element name="Coun +ty" type="String21" /> </xs:sequence>- <xs:attribute name="AddressType">- <xs:simpleType>- <xs:restriction base="xs:string"> <xs:enumeration value="Street" /> <xs:enumeration value="Mailing" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>- <xs:simpleType name="String11">- <xs:restriction base="xs:string"> <xs:maxLength value="11" /> </xs:restriction> </xs:simpleType>- <xs:simpleType name="String4">- <xs:restriction base="xs:string"> <xs:maxLength value="4" /> </xs:restriction> </xs:simpleType>- <xs:simpleType name="String2">- <xs:restriction base="xs:string"> <xs:maxLength value="2" /> </xs:restriction> </xs:simpleType>- <xs:simpleType name="String1">- <xs:restriction base="xs:string"> <xs:maxLength value="1" /> </xs:restriction> </xs:simpleType>- <xs:simpleType name="String80">- <xs:restriction base="xs:string"> <xs:maxLength value="80" /> </xs:restriction> </xs:simpleType>- <xs:simpleType name="String30">- <xs:restriction base="xs:string"> <xs:maxLength value="30" /> </xs:restriction> </xs:simpleType>- <xs:simpleType name="String21">- <xs:restriction base="xs:string"> <xs:maxLength value="21" /> </xs:restriction> </xs:simpleType> </xs:schema>
I would like to take part of schema and load it into a
mysql table:
id, phone, fax, city, county, zip
I am tyring to figure out XML::XPath as way to do this. I am guessing that I need to ->find('//Associationid')
as well as the other nodes and them push them into a hash.
They loop through the hash and load the values into the
table. However, I am little confused about to get all of
the values together.
my $xp=XML::XPath->new(filename=>$file); my $hash; my $id=$xp->find('//Associationid'); my $phone->find('//OfficePhone'); ... ... if ($id->get_nodelist){ $hash{$id}{$phone}{$fax}{$county}{$zip}; }
This is causing the following error:
Can't call method "get_nodelist" on an undefined value
Is this even the best approach? How about the next xml
file when I need to load all elements?
Is XML::LibXML better?

Thanks. Tony

In reply to loading xml into mysql by ctaustin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.