Solved

using xml and classic asp

Posted on 2014-04-04
13
787 Views
Last Modified: 2014-04-04
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("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://www.dictionaryapi.com/api/v1/references/learners/xml/"&strMyWord&"?key=xxxxxxxxxxxxxxx")
 
Set itemList = XMLDom.SelectNodes("hw")


 
For Each itemAttrib In itemList
   strNewWord =itemAttrib.SelectSingleNode("hw").text
   strNewSound =itemAttrib.SelectSingleNode("sound").text
   %>
   <tr>
           <td>This is static</td>
      <td><%=strNewWord%></td>
      <td><%=strNewSound%></td>
   </tr>
<%
Next
 
Set xmlDOM = Nothing
Set itemList = Nothing
0
Comment
Question by:Abiel de Groot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977495
Sorry...   This is their example xml response:

<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>
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39977595
This:
Set itemList = XMLDom.SelectNodes("hw")

Open in new window

Should probably be:
Set itemList = XMLDom.SelectNodes("entry")

Open in new window

Assuming you are trying to sow just the "hw" and "sound" elements of each "entry".
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977634
it makes no difference.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977641
Would you lie me to send you the API key so you can try it?

A.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39977651
If you can, that would be helpful. Is there any more to the XML? Namely any higher level nodes, or an XML declaration?
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977663
I sent you a private message in Facebook ;-)

A
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977664
I really appreciate your advice on this. I am stuck :-)
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39977708
Ah, ok, your XML has a higher level root node, which you need to take account of in your SelectNodes call:
<%
Dim xmlDOM, itemList, strNewWord, strNewSound, itemAttrib, strMyWord

strMyWord = "wonderful"

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=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

Set itemList = XMLDom.SelectNodes("entry_list/entry")
 
For Each itemAttrib In itemList
   strNewWord =itemAttrib.SelectSingleNode("hw").text
   strNewSound =itemAttrib.SelectSingleNode("sound").text
%>
   <tr>
           <td>This is static</td>
      <td><%=strNewWord%></td>
      <td><%=strNewSound%></td>
   </tr>
<%
Next
 
Set xmlDOM = Nothing
Set itemList = Nothing
%>

Open in new window

For reference, this is the full XML you are receiving:
<?xml version="1.0"?>
<entry_list version="1.0">
	<entry id="wonderful">
		<hw highlight="yes">won*der*ful</hw>
		<sound><wav>wonder03.wav</wav></sound>
		<pr>'w?nd?f?l</pr>
		<fl>adjective</fl>
		<def><gram>more won*der*ful; most won*der*ful</gram>
			<dt>:extremely good <vi>The rooms were filled with <it>wonderful</it> works of art.</vi>
				<vi>It was a <it>wonderful</it> party.</vi>
				<vi>You did a <it>wonderful</it> job.</vi>
				<vi>We had a <it>wonderful</it> [=<it>great</it>, <it>terrific</it>, <it>fantastic</it>] meal.</vi>
				<vi>She came home with <it>wonderful</it> news.</vi>
				<vi>It's <it>wonderful</it> to finally meet you.</vi></dt></def>
		<uro><ure>won*der*ful*ly</ure>
			<fl>adverb</fl>
			<utxt><vi>The story was <it>wonderfully</it> written.</vi></utxt></uro></entry>
</entry_list>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39977727
This is tested and works

<%
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
%>

Open in new window


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>'&#xE6;p&#xBF;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>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39977735
Well, looks like you have two similar answers.   I had registered for a key to figure this out.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39977740
I was too lazy to do that :)
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977742
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
0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 39977746
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question