Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Asp parse XML feed

Status
Not open for further replies.
You can use this
Code:
strURL = "[URL unfurl="true"]http://www.conviveon.com/xml/index?page=xmlfeed&channel=press_release"[/URL]
Set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.5.0")
objXMLHTTP.Open "GET", strURL, false
objXMLHTTP.send  
lStrContent =  objXMLHTTP.responseText
Set objXMLHTTP = Nothing
Response.Write lStrContent

Also you would need the lastest Msxml2.XMLHTTP object
if thism doesnt work you can try

Set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP")
or
Set objXMLHTTP = Server.CreateObject("Msxml.XMLHTTP")

or the best way is to make a search into registry and look for the Msxml and XMLHTTP words.


________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thank u for you quick response.
Msxml2.XMLHTTP works. Is there a way to format the output? If you could show an example, would appreciate.

Thank u again
 
Ah, now i understant what you ment, i didnt cheked the link to see that you already have an XML file.
To make that output you would need to use and XSL file.
Do you want to use XML file as an database? for your ASP?

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Yes sir.

Is there any kind of documentation or book that i can read to get some sort of knowledge on asp and xml?
 
Ok i'll post an example here
XML file and ASP one

data.xml file
------- content -------
Code:
<?xml version="1.0"?>
<PAGE>
<PAGE id="1">
    <LANGUAGE id="17" name="Eng">
      <NAME>name 1 Eng</NAME>
    </LANGUAGE>
    <LANGUAGE id="16" name="Swe">
      <NAME>name 1 swe</NAME>
    </LANGUAGE>
    <LANGUAGE id="17" name="Eng">
      <TEXT>text 2 Eng</TEXT>
      <NAME>name 2 Eng</NAME>
    </LANGUAGE>
  <TEXT>
    <LANGUAGE id="16" name="Swe">
      <TEXT>text 2 Eng</TEXT>
      <NAME>name 2 Eng</NAME>
    </LANGUAGE>
  </TEXT>
  <IMAGE>
    <LANGUAGE id="17" name="Eng">
      <VERSION>
        <FILE>file 1 Eng</FILE>
        <NAME>version name 1 Eng</NAME>
        <EXTENSION>text 1 Eng</EXTENSION>
      </VERSION>
    </LANGUAGE>
  </IMAGE>
  <ARTICLE>
    <LANGUAGE id="17" name="Eng">
      <NAME>article 1 Eng</NAME>
    </LANGUAGE>
  </ARTICLE>
  <ARTICLE>
    <ATTRIBUTE>
      <LANGUAGE id="17" name="Eng">
        <NAME>attrib 1 Eng</NAME>
      </LANGUAGE>
    </ATTRIBUTE>
  </ARTICLE>
<PAGE>
    <LANGUAGE id="17" name="Eng">
      <NAME>name 2 Eng</NAME>
    </LANGUAGE>
</PAGE>
</PAGE>


<PAGE id="2">
    <LANGUAGE id="17" name="Eng">
      <NAME>name 1 Eng (page 2)</NAME>
    </LANGUAGE>
    <LANGUAGE id="16" name="Swe">
      <NAME>name 1 swe (page 2)</NAME>
    </LANGUAGE>
    <LANGUAGE id="17" name="Eng">
      <TEXT>text 2 Eng (page 2)</TEXT>
      <NAME>name 2 Eng (page 2)</NAME>
    </LANGUAGE>
  <TEXT>
    <LANGUAGE id="16" name="Swe">
      <TEXT>text 2 Eng (page 2)</TEXT>
      <NAME>name 2 Eng (page 2)</NAME>
    </LANGUAGE>
  </TEXT>
  <IMAGE>
    <LANGUAGE id="17" name="Eng">
      <VERSION>
        <FILE>file 1 Eng (page 2)</FILE>
        <NAME>version name 1 Eng (page 2)</NAME>
        <EXTENSION>text 1 Eng (page 2)</EXTENSION>
      </VERSION>
    </LANGUAGE>
  </IMAGE>
  <ARTICLE>
    <LANGUAGE id="17" name="Eng">
      <NAME>article 1 Eng (page 2)</NAME>
    </LANGUAGE>
  </ARTICLE>
  <ARTICLE>
    <ATTRIBUTE>
      <LANGUAGE id="17" name="Eng">
        <NAME>attrib 1 Eng (page 2)</NAME>
      </LANGUAGE>
    </ATTRIBUTE>
  </ARTICLE>
<PAGE>
    <LANGUAGE id="17" name="Eng">
      <NAME>name 2 Eng (page 2)</NAME>
    </LANGUAGE>
</PAGE>
</PAGE>

</PAGE>

index.asp file
--------content--------
Code:
<%
   Set objXML = Server.CreateObject("Microsoft.XMLDOM") 
   objXML.async = False                 ' optional 
   objXML.validateOnParse = False       ' optional 
   objXML.Load(Server.MapPath("data.xml"))

Set objLst = objXML.getElementsByTagName("PAGE")
i = 0 
Dim iCounter
iCounter = 1

Dim lang_nodes, t_node
For each objNode in objLst

Response.Write("Page nr ") & iCounter & ("<br><br>")

    'page information section
    Set lang_nodes = objNode.SelectNodes("LANGUAGE")
    For Each t_node in lang_nodes
        If t_node.getAttribute("id") = "17" Then
            Response.Write "Name: " & t_node.SelectSingleNode("NAME").Text & "<br>"
        End If
    Next
    Set lang_nodes = Nothing

    'now do the text section
    Set lang_nodes = objNode.SelectNodes("TEXT/LANGUAGE")
    For Each t_node in lang_nodes
        If t_node.getAttribute("id")= "17" Then
          Response.Write "Name: " & t_node.SelectSingleNode("NAME").Text & "<br>"
          Response.Write t_node.SelectSingleNode("TEXT").Text & "<br>"
        End If
    Next


Dim img_nodes, img_node
Set img_nodes = objNode.SelectNodes("IMAGE/LANGUAGE")
For Each img_node in img_nodes

    'Check for the LANGUAGE id = 17
    If img_node.getAttribute("id") = "17" Then
    
        'get the VERSION node from inside the IMAGE/LANGUAGE node
        Set t_node = img_node.SelectSingleNode("VERSION")

        'get the values of whatever you need here from t_node, for example
        Dim strImage
        strImage = (t_node.SelectSingleNode("FILE").Text)
        strImage = strImage & (t_node.SelectSingleNode("NAME").Text)
        strImage = strImage & "." & (t_node.SelectSingleNode("EXTENSION").Text)
        Response.Write(strImage) & "<br>"
        'Response.Write "    Image Extension: " & t_node.SelectSingleNode("EXTENSION").Text & "<br>"
        'or for the name attribute
        Response.Write "    Name Attr: " & t_node.getAttribute("name") & "<br>"
    End If
Next



    'now do the article section
    Set article_nodes = objNode.SelectNodes("ARTICLE/LANGUAGE")
    For Each t_node in article_nodes
        If t_node.getAttribute("id")= "17" Then
          Response.Write "Name: " & t_node.SelectSingleNode("NAME").Text & "<br>"
        End If
    Next

    'now do the article section
    Set attrib_nodes = objNode.SelectNodes("ARTICLE/ATTRIBUTE/LANGUAGE")
    For Each t_node in attrib_nodes
        If t_node.getAttribute("id")= "17" Then
          Response.Write "Name: " & t_node.SelectSingleNode("NAME").Text & "<br>"
        End If
    Next

iCounter = iCounter + 1  
Next 
%>
I hope this helps
I havent got time to make an simple example but here should be all what you need. You can find more
and



________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thank you sir. You are a master and a scholar. Appreciate all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top