XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 26th, 2003, 06:47 PM
zewt's Avatar
zewt zewt is offline
PHP user-in-training
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2001
Location: Sacramento Calif. USA
Posts: 618 zewt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 43 m 58 sec
Reputation Power: 7
XML DOM questions. in case anyone is looking...

I am trying to bone up on XML, and have been reading the tutorials posted here and W3S and others.

I am trying to parse through some XML files that have multiple siblings... But cannot seem to fins out how to get the DOM to see these siblings.

here is an example

PHP Code:
<main>
    <
updated>Mon Feb 17 13:17:59 2003</updated>
    <
baseinfo>
        <
stata>60</stata>
        <
statb>70</statb>
        <
statc>83</statc>
    </
baseinfo>
    <
equipment>
        <
inventory>
            <
item>
                <
devicea>1334</devicea>
                <
deviceb>5713</deviceb>
                <
devicec>234 
            
</devicec>
            </
item>
                                </
inventory>
    </
equipment>
</
main


I have been using some of the DOM test examples but cannot seem to parse out the info from the statx siblings.

I can get info from the higher level child nodes but nothing from the lower nodes. I am kind of stuck atm.

code such as this:

PHP Code:
<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")

for 
each x in xmlDoc.documentElement.childNodes
    document
.write(x.nodeName "<br />")
next
</script>
 


will not show me the lowest level node info.

Reply With Quote
  #2  
Old February 27th, 2003, 11:15 PM
customfittech customfittech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: St. Louis, MO USA
Posts: 43 customfittech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Your script is only iterating through the first level of children.

In order to get to the "root" of the problem (ha ha,) use this code instead:

<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")

set xmlRootNode = xmlDoc.documentElement
set xmlNodeList = xmlRootNode.selectNodes("/main/baseinfo/*")

For i = 0 To xmlNodeList.length - 1
document.write(xmlNodeList.Item(i).nodeName & "<br />")
Next
</script>

I haven't tested it, but the basic idea is, xpath a selectNodes statement to the level you need. I can give you more help or specifics if you need it.
__________________
- Chris of Custom Fit Technology
http://www.customfittech.com

Access to MySQL Conversion Tool,
Visual XSLT Conversion Tool

Reply With Quote
  #3  
Old February 27th, 2003, 11:16 PM
customfittech customfittech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: St. Louis, MO USA
Posts: 43 customfittech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Forgot this: If you want to cycle through all the children, create a recursive function.

Reply With Quote
  #4  
Old February 28th, 2003, 06:11 PM
zewt's Avatar
zewt zewt is offline
PHP user-in-training
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2001
Location: Sacramento Calif. USA
Posts: 618 zewt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 43 m 58 sec
Reputation Power: 7
Thumbs up

Thanks for the tips Custom, I will have to play with this this weekend, as these concepts are a tad new to me.

Reply With Quote
  #5  
Old March 1st, 2003, 06:53 PM
customfittech customfittech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: St. Louis, MO USA
Posts: 43 customfittech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I would be happy to email you some example VBScript code along with lists of necessary libraries if you require additional assitance.

Reply With Quote
  #6  
Old April 25th, 2003, 07:46 AM
ssvr6 ssvr6 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Boca Raton, FL
Posts: 35 ssvr6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via Yahoo to ssvr6
I'm having a similar problem with reading a file. The example you listed doesn't really apply to me. I searched and this was the closest thing I could find...


PHP Code:
<Questions>
    <
Question sequence="0">
        <
QuestionText>How old are you?</QuestionText
        <
Answers>
            <
Answer sequence="1" correct="N">
                <
AnswerText>20</AnswerText
            </
Answer>
            <
Answer sequence="2" correct="N">
                <
AnswerText>22</AnswerText
            </
Answer>
            <
Answer sequence="3" correct="N">
                <
AnswerText>28</AnswerText
            </
Answer>
            <
Answer sequence="4" correct="Y">
                <
AnswerText>27</AnswerText
            </
Answer>
            <
Answer sequence="5" correct="N">
                <
AnswerText>None of the above</AnswerText
            </
Answer>
        </
Answers>
    </
Question>
</
Questions


I'm trying to get to the Question Text and the answers. Here's what I'm trying that's not working.


PHP Code:
 Set obj_questions objXMLReceive.getelementsbytagname("Question")

For 
0 to obj_questions.length 1
    Set obj_question 
obj_questions(i)
    
s_questxt  obj_question.selectSingleNode("QuestionText")
    
myArray(i) = s_questxt
    
    Set obj_answers 
objXMLReceive.getelementsbytagname("Answers")
    For 
0 to obj_answers.length 1
        Set obj_answer 
obj_answers(j)
        
s_answertxt  obj_answer.selectSingleNode("Answer")
        
s_correct    obj.answer.getAttribute("correct")
        
myAnswers(j) = s_answertxt
    Next
    
Next 


My error occurs here:
PHP Code:
 s_questxt  obj_question.selectSingleNode("QuestionText"


Any and all help would be appreciated.

Thanks,

Steve
__________________
Web Application Developer
Autotrack XP
Automobile Enthusiast
QuickVWs.com
K-Series.com

Reply With Quote
  #7  
Old April 25th, 2003, 10:35 AM
customfittech customfittech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: St. Louis, MO USA
Posts: 43 customfittech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
the error probably occurs because you're selecting a node object into a text variable. I would try something like

s_questxt = obj_question.selectSingleNode("QuestionText\text()")

Or use a two step method to set x = node object, then get the text property of that object. I'm short on time right now so there's not a lot of code in this reply, but I hope it helps!

Reply With Quote
  #8  
Old April 25th, 2003, 11:12 AM
ssvr6 ssvr6 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Boca Raton, FL
Posts: 35 ssvr6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via Yahoo to ssvr6
Thanks! I actually found the answer while I was playing around. Thanks,


Steve

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML DOM questions. in case anyone is looking...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway