Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parsing XML with DOM
Message
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Environment versions
Visual FoxPro:
VFP 7
Miscellaneous
Thread ID:
00962465
Message ID:
00963774
Views:
11
This message has been marked as the solution to the initial question of the thread.
Hi Don,

Valid XML (for testing)
<?xml version='1.0' encoding='utf-8'?>
<SOAP-ENV:Envelope
  xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'>

 <SOAP-ENV:Body>
  <ns1:downloadResponse
    SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'
    xmlns:ns1='urn:TMSWebServices' >

   <xtvdResponse xsi:type='ns1:xtvdResponse'>
    <messages xsi:type='ns1:messages'>
     <message>The endTime you specified 07:00:00Z is not in a valid format,
       and has been corrected to a default value.</message>
     <message>The endTime you specified was invalid and has been corrected to 2004-11-27T07:00:00Z.</message>
     <message>Your subscription will expire: 2005-01-29T23:55:24Z</message>
    </messages>
    <xtvdDocument xsi:type='ns1:xtvd'>
     <xtvd from='2004-11-22T07:00:00Z' to='2004-11-27T07:00:00Z' schemaVersion='1.3'
      xmlns='urn:TMSWebServices'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:schemaLocation='urn:TMSWebServices http://docs.tms.tribune.com/tech/xml/schemas/tmsxtvd.xsd'>
      <stations>
       <station id='10021'>
        <callSign>AMC</callSign>
        <name>AMC</name>
        <affiliate>Satellite</affiliate>
       </station>
      </stations>

      <schedules>
       <schedule program='EP1151270200' station='11867' time='2004-11-17T01:00:00Z'
        duration='PT00H30M' tvRating='TV-PG' stereo='true' closeCaptioned='true'/>
       <schedule program='EP1151270201' station='11867' time='2004-11-17T01:30:00Z'
        duration='PT00H30M' tvRating='TV-PG' stereo='true' closeCaptioned='true'/>
       <schedule program='EP2654380045' station='11867' time='2004-11-17T02:00:00Z'
        duration='PT00H30M' tvRating='TV-14' stereo='true' closeCaptioned='true'/>
       <schedule program='EP2654380046' station='11867' time='2004-11-17T02:30:00Z'
        duration='PT00H35M' tvRating='TV-14' stereo='true' closeCaptioned='true'/>
       <schedule program='EP6892960005' station='11867' time='2004-11-17T03:05:00Z'
        duration='PT01H00M'/>
       <schedule program='EP4638260091' station='12131' time='2004-11-17T01:30:00Z'
        duration='PT00H30M' tvRating='TV-Y7' stereo='true' closeCaptioned='true'>
        <part number='1' total='2'/>
       </schedule>
       <schedule program='MV1032330000' station='11867' time='2004-11-17T04:05:00Z'
        duration='PT01H45M' tvRating='TV-14' closeCaptioned='true'/>
       <schedule program='MV1032330000' station='11867' time='2004-11-17T05:50:00Z'
        duration='PT01H45M' tvRating='TV-14' closeCaptioned='true'/>
       <schedule program='MV0280340000' station='11867' time='2004-11-17T07:35:00Z'
        duration='PT02H00M' tvRating='TV-PG' closeCaptioned='true'/>
       <schedule program='SH2148780000' station='11867' time='2004-11-17T09:35:00Z'
        duration='PT00H25M'/>
       <schedule program='EP1282610060' station='11867' time='2004-11-17T10:00:00Z'
        duration='PT00H30M' tvRating='TV-PG' stereo='true' closeCaptioned='true'/>
       <schedule program='EP1900270045' station='11867' time='2004-11-17T10:30:00Z'
        duration='PT00H30M' tvRating='TV-PG' stereo='true' closeCaptioned='true'/>
      </schedules>
     </xtvd>
    </xtvdDocument>
   </xtvdResponse>
  </ns1:downloadResponse>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Program:
loXML=CREATEOBJECT("Microsoft.XMLDOM")
loXML.async=.F.
loXML.SetProperty("SelectionLanguage","XPath")

If loxml.load("e:\don3.XML")
   * All schedule elements
   loxx=loxml.documentElement.selectNodes("*/*/*/*/*/*[local-name()='schedules']/*[local-name()='schedule']")

*   loXML.setProperty("SelectionNamespaces", [xmlns:ns1="urn:TMSWebServices"])
*   loxx=loxml.documentElement.selectNodes("*/ns1:downloadResponse/*/*/*/*[local-name()='schedules']/*[local-name()='schedule']")

   FOR lii=0 to loxx.length-1
       loNode=loxx.item(lii)
       ?"UTF-8      ",;
         loNode.GetAttribute("program"),;
         loNode.GetAttribute("station"),;
         loNode.GetAttribute("time")
       ?"CPCURRENT()",;
         STRCONV(loNode.GetAttribute("program"),11),;
         STRCONV(loNode.GetAttribute("station"),11),;
         loNode.GetAttribute("time")
   next
endif
MartinJ

>Martin -
>Thanks again for your code sample. I am slowly working my way through and making some progress. Your code will work fine with the sample file but does not work with the real file which is much bigger. I believe the reason for this is because the real file has additional header information at the beginning, so I expect the pathing to the data sections needs to be adjusted. The complete header is as follows:
>
>
><?xml version='1.0' encoding='utf-8'?>
><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
 xmlns:xsd='http://www.w3.org/2001/XMLSchema'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'>
>....
>
>
>This includes the first record for stations which is where my data begins. The are just for information and not a true part of the data. Could you suggest how to modify your previous code to get it to work with the above header? I have the tmsxtvd.xsd file but it offers no help to me since I am too much of a beginner.
>
>Thanks again.
>- Don
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform