Abiel de Groot
asked on
using xml and classic asp
Hi All,
I have used xml in actionscript before, but I now find myself trying to integrate a tool with XML in classic ASP.
I really need some advice and pointers. (I am starting from scrath!)
I have an API key to use an English Dictionary to send it a word and it should present me with some xml containing definitions, links to wav files containing pronunciation, synonyms, antonyms etc.
They kindly supplied a sample xml snippet and a more detailed file of the actual xml structure.
I am now not getting any errors, but neither am I getting any results. This is what I have:
---
Dim xmlDOM, itemList, strNewWord, strNewSound, itemAttrib, strMyWord
strMyWord = "wonderful"
Set xmlDOM = Server.CreateObject("MSXML 2.DOMDocum ent")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://www.dictionaryapi.com/api/v1/references/learners/xml/"&strMyWord&" ?key=xxxxx xxxxxxxxxx ")
Set itemList = XMLDom.SelectNodes("hw")
For Each itemAttrib In itemList
strNewWord =itemAttrib.SelectSingleNo de("hw").t ext
strNewSound =itemAttrib.SelectSingleNo de("sound" ).text
%>
<tr>
<td>This is static</td>
<td><%=strNewWord%></td>
<td><%=strNewSound%></td>
</tr>
<%
Next
Set xmlDOM = Nothing
Set itemList = Nothing
I have used xml in actionscript before, but I now find myself trying to integrate a tool with XML in classic ASP.
I really need some advice and pointers. (I am starting from scrath!)
I have an API key to use an English Dictionary to send it a word and it should present me with some xml containing definitions, links to wav files containing pronunciation, synonyms, antonyms etc.
They kindly supplied a sample xml snippet and a more detailed file of the actual xml structure.
I am now not getting any errors, but neither am I getting any results. This is what I have:
---
Dim xmlDOM, itemList, strNewWord, strNewSound, itemAttrib, strMyWord
strMyWord = "wonderful"
Set xmlDOM = Server.CreateObject("MSXML
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://www.dictionaryapi.com/api/v1/references/learners/xml/"&strMyWord&"
Set itemList = XMLDom.SelectNodes("hw")
For Each itemAttrib In itemList
strNewWord =itemAttrib.SelectSingleNo
strNewSound =itemAttrib.SelectSingleNo
%>
<tr>
<td>This is static</td>
<td><%=strNewWord%></td>
<td><%=strNewSound%></td>
</tr>
<%
Next
Set xmlDOM = Nothing
Set itemList = Nothing
This:
Set itemList = XMLDom.SelectNodes("hw")
Should probably be:Set itemList = XMLDom.SelectNodes("entry")
Assuming you are trying to sow just the "hw" and "sound" elements of each "entry".
ASKER
it makes no difference.
ASKER
Would you lie me to send you the API key so you can try it?
A.
A.
If you can, that would be helpful. Is there any more to the XML? Namely any higher level nodes, or an XML declaration?
ASKER
I sent you a private message in Facebook ;-)
A
A
ASKER
I really appreciate your advice on this. I am stuck :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is tested and works
It helps to expand the xml and you can see the tree structure.
<%
strMyWord = "apples"
strKey = "YOUR_OWN_KEY"
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://www.dictionaryapi.com/api/v1/references/learners/xml/"&strMyWord&"?key="&strKey)
Set hw = XMLDom.SelectNodes("entry_list/entry/hw")
set sound = XMLDom.SelectNodes("entry_list/entry/sound/wav")
For Each itemAttrib In hw
response.write itemAttrib.text &"<br>"
Next
For Each itemAttrib In sound
response.write itemAttrib.text &"<br>"
Next
Set xmlDOM = Nothing
Set hw = Nothing
%>
It helps to expand the xml and you can see the tree structure.
<?xml version="1.0"?>
<entry id="apple">
<hw highlight="yes">ap*ple</hw>
<sound>
<wav>apple001.wav</wav>
</sound>
<pr>'æp¿l</pr>
<fl>noun</fl>
<in>
<il>plural</il>
<if>ap*ples</if>
</in>
<def>
<dt>:a round fruit with red, yellow, or green skin and firm white flesh <wsgram>count</wsgram>
<vi>crisp juicy <it>apples</it>
</vi>
<vi>a bad/rotten <it>apple</it> [=an apple that has rotted and cannot be eaten]</vi>
<wsgram>noncount</wsgram>
<vi>a piece of <it>apple</it>
</vi>
<un>often used before another noun <vi>
<it>apple</it> pie</vi>
<vi>
<it>apple</it> juice</vi>
<vi>
<it>apple</it> trees</vi>
</un>
<dx>see color picture on page C5</dx>
<snote>In figurative use, a <phrase>bad apple</phrase> or <phrase>rotten apple</phrase> is a bad member of a group who causes problems for the rest of the group. <vi>A few <it>bad apples</it> cheated on the test, and now everyone has to take the test again.</vi>
<vi>One <it>rotten apple</it> ruined the day for the rest of us.</vi>
</snote>
<dx>see also <dxt>adam's apple</dxt>
<dxt>crab apple</dxt>
</dx>
</dt>
</def>
<dro>
<dre>compare apples to apples/oranges</dre>
<dx>see <dxt>compare</dxt>
</dx>
</dro>
<dro>
<dre>the apple of someone's eye</dre>
<def>
<dt>:a person or thing that someone loves very much <vi>His daughter is <it>the apple of his eye</it>.</vi>
</dt>
</def>
</dro>
<dro>
<dre>upset the apple cart</dre>
<dx>see <dxt>upset</dxt>
</dx>
</dro>
</entry>
Well, looks like you have two similar answers. I had registered for a key to figure this out.
I was too lazy to do that :)
ASKER
Many thanks. Not only for the answer but for outlining how to do it in the future. I really appreciate it.
Abiel M de Groot
Abiel M de Groot
ASKER
Sorry Scott. Carl was at this first and came up with the right answer. I did not see your entry until too late.
Kind regards
A
Kind regards
A
ASKER
<entry id="apple"> <hw highlight="yes">ap*ple</hw