Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading through an XML file


Hi

I was wondering you can provide me with some help. As a non programmer
I'm pleased I've managed to
cobble together some code which reads in an XML file but I'm struggling
to look
at anything other than the first record (of many. Here is an example of
the xml of
which there can be up to 10 records......

<records type="array"
<record
<offer
<value type="decimal"7.6</value
<for type="decimal"1.16</for
</offer
<seller
<Number type="integer"24</Number
<is-valid type="boolean"false</is-valid
<nameSmith</name
<is-correct type="boolean"false</is-correct
</seller
</record
<record
<offer
<value type="decimal"2.03</value
<for type="decimal"1.163</for
</offer
<seller
<Number type="integer"184</Number
<is-valid type="boolean"false</is-valid
<nameJones</name
<is-correct type="boolean"true</is-correct
</seller
</record

What I want to do is to identify if the word, say, "Jones" appears in
any seller elements by reading through
the relevant records. It can appear in any or none of the "records".
Can anyone help?

Here is the relevant bits of my code (I hope!!!)

Dim oXML As Object
Dim oDom As Object
Dim strResponse As String
Dim strURL As String

On Error GoTo Handler
Set oXML = CreateObject("Microsoft.XMLHTTP")

With oXML
Open "GET", strURL, False
'Needed to web service will recognize get/post
setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
send
End With

'get the results
strResponse = oXML.responseText

Set oDom = CreateObject("MSXML.DOMDocument")
oDom.LoadXML (strResponse)

' Check to see if there is an entry
If oDom.DocumentElement.nodeName = "nil-classes" Then
' nothing there interesting
mydata = 0
Else
' This sections adds detail to the spreadsheet where there is an
existing sale offer and provide details
mydata =
oDom.DocumentElement.SelectSingleNode("record/offer/for").Text
' SOMEWHERE / SOMEHOW HERE I NEED TO LOOP THROUGH THE XML
RECORDS BUT I CAN ONLY READ THE FIRST!
END IF


Many thanks for your help!!!!

DEC


--
dec3
------------------------------------------------------------------------
dec3's Profile: 1398
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=172361

Microsoft Office Help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Reading through an XML file

On 21/01/2010 23:14, dec3 wrote:
Hi


<snip

' This sections adds detail to the spreadsheet where there is an
existing sale offer and provide details
mydata =
oDom.DocumentElement.SelectSingleNode("record/offer/for").Text
' SOMEWHERE / SOMEHOW HERE I NEED TO LOOP THROUGH THE XML
RECORDS BUT I CAN ONLY READ THE FIRST!
END IF


You need the selectNodes method. That returns a NodesList which ye can
wander down using the .nextNode method once found how many in the list.

Set oNList = oNode.selectNodes("record/offer/for")

nTot = oNList.length - 1

For nCnt = 0 to nTot

Set oThisNode = oXMLTreeList.nextNode()

' do whatever here for each node

Next

--
Adrian C
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Reading through an XML file

On 21/01/2010 23:36, Adrian C wrote:
Set oNList = oNode.selectNodes("record/offer/for")

nTot = oNList.length - 1

For nCnt = 0 to nTot

Set oThisNode = oXMLTreeList.nextNode()

' do whatever here for each node

Next


Whoops, bad cut n paste

Set oThisNode = oNList.nextNode()



--
Adrian C
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reading through an XML file


Adrian C;620012 Wrote:
On 21/01/2010 23:36, Adrian C wrote:
Set oNList = oNode.selectNodes("record/offer/for")

nTot = oNList.length - 1

For nCnt = 0 to nTot

Set oThisNode = oXMLTreeList.nextNode()

' do whatever here for each node

Next


Whoops, bad cut n paste

Set oThisNode = oNList.nextNode()



--
Adrian C


Hi Adrian / Others

Sorry to continue to be thick on this but I now get msg "Object
Required"

Here is my updated code...

Set oNList = oNode.SelectNodes("record/offer/for")

nTot = oNList.Length - 1

For nCnt = 0 To nTot

Set oThisNode = oNList.NextNode()

' do whatever here for each node

mytext =
oDom.DocumentElement.SelectNodes("record/seller/name").Text

If mytext = "Jones" Then
' do stuff
End If
MsgBox (mytext)

Next

Any ideas please?
DEC


--
dec3
------------------------------------------------------------------------
dec3's Profile: 1398
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=172361

Microsoft Office Help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading from a file Ernst Guckel[_4_] Excel Programming 6 March 21st 07 06:00 PM
reading txt file and copying the lines in new excel file [email protected] Excel Programming 2 August 11th 06 07:20 PM
reading from another file and pasting to current file, "combobox" Darius New Users to Excel 1 September 26th 05 07:13 AM
reading data from 2nd file in 1st file using Combobox Darius Excel Programming 0 September 22nd 05 04:51 PM
reading from text file to excel file dgoel Excel Programming 0 April 18th 05 06:49 PM


All times are GMT +1. The time now is 10:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"