Sign in to follow this  
Followers 0
SummerGirl

Extracting values from xml

3 posts in this topic

Dear all,

     Need some help with extracting the values from xml file.

I am newbee...and want some help.

I want to extract all the TotalStudyTime for every student 1,2

and output to a particular cell in Excel

Please let me know how to proceed.

I browsed _XMLDomWrapper.au3 but please let me know where

I can download and how to use them to extract attibute.

Thanks in advance.

My XML file:(StudentTime.xml)
<?xml version="1.0" encoding="utf-8"?>
<StudyTime>
  <Student Name="1" TopGrade="False">
    <Class10>
      <Physics>
        <StudyTime="4" ExperimentTime="1" />
      </Physics>
      <Chemistry>
        <StudyTime="3" ExperimentTime="3" />
      </Chemistry>
      <Total>
        < PhysicsTotalTime="5"  ChemistryTotalTime="6" TotalStudyTime="11"/>
      </Total>
    </Class10>
    </Student>
      <Student Name="2" TopGrade="False">
    <Class10>
      <Physics>
        <StudyTime="5" ExperimentTime="1" />
      </Physics>
      <Chemistry>
        <StudyTime="5" ExperimentTime="3" />
      </Chemistry>
      <Total>
        < PhysicsTotalTime="6"  ChemistryTotalTime="8" TotalStudyTime="14"/>
      </Total>
    </Class10>
    </Student>
</StudyTime>

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If no one else is going to help - try this for a start: 

#include <Array.au3>

Local $file = FileOpen("StudentTime.xml", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$XML = FileRead($file)

$array = StringRegExp($XML, '(?i)(?-s)<Student Name="(.*?)"(?s).*?(?s)TotalStudyTime="(\d+)', 3)

_ArrayDisplay($array, 1)

FileClose($file)

of course you'll have to put the directory path to your file or use _INetGetSource to grab the data - now you've got the data you can try out the various options for keeping it Excel etc.

Edited by Jury

Share this post


Link to post
Share on other sites
I browsed _XMLDomWrapper.au3 but please let me know where

I can download and how to use them to extract attibute.

What do you mean by "download"? If you browsed the UDF then you already did a download.

Most of the time you find a UDF on the first post of a thread. In this case >here.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0