[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

I need help parsing data into an ASP page from a remote XML (RDF) page

Hi,

I am currently trying to accomplish the task of parsing data from a XML page without success. I use ASP and my setup is currently:

-------------------------------------------------------------------------------------------------------------------
Dim poXMLHTTP, poXMLDOM

Set poXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
      poXMLHTTP.Open "GET", "http://nds.nokia.com/uaprof/N6610r100.xml", False, "", ""
      poXMLHTTP.Send
      
      Set poXMLDOM = Server.CreateObject("Microsoft.XMLDOM")
            poXMLDOM.async = False            
            poXMLDOM.load(poXMLHTTP.responseXML)
            
            If poXMLDOM.parseError <> 0 Then
                  response.Write poXMLDOM.parseError.reason
            Else            
                  response.Write poXMLDOM.selectSingleNode("//BitsPerPixel").Text      
            End If
            
      Set poXMLDOM = Nothing
Set poXMLHTTP = Nothing
-------------------------------------------------------------------------------------------------------------------

The response i get is an error message that states: XML document must have a top level element.

I am not very skilled in XML so there might be a simple answer to this, but after sitting constantly for two days looking on the net I have not found an answer to this. Help i greatly appreciated!
0
Hasner
Asked:
Hasner
  • 5
  • 4
1 Solution
 
b1xml2Commented:
<%@Language="VBScript"%>
<%
Dim http
Dim document
Dim namespaces
Dim node
Dim xpath

Set http = Server.CreateObject("Msxml2.XMLHTTP")
http.Open "GET", "http://nds.nokia.com/uaprof/N6610r100.xml", False
http.Send

Set document = Server.CreateObject("Msxml2.DOMDocument")
document.async = False
document.validateOnParse = False
document.resolveExternals = False
document.load http.responseBody

namespaces = "xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' " & _
            "xmlns:prf='http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#' " & _
            "xmlns:mms='http://www.wapforum.org/profiles/MMS/ccppschema-20010111#' "
            
document.setProperty "SelectionLanguage","XPath"
document.setProperty "SelectionNamespaces",namespaces

xpath = "//prf:BitsPerPixel"
Set node = document.selectSingleNode(xpath)

If Not node Is Nothing Then
      Response.Write node.Text
Else
      Response.Write "empty"
End If

Set document = Nothing
Set http = Nothing
%>



0
 
HasnerAuthor Commented:
Thanks alot for the quick response! Really appreciate it, but I still have a question. The solution given worked like a charm, but what I forgot to state in the opening question was that I wanted to make the code so that I was able to use it with different UAProf's. See this link for details:

http://w3development.de/rdf/uaprof_repository/

I want to end up with a code snippet where i only have to change the URL to the xml file and the selected node.

URL: http://nds.nokia.com/uaprof/N6610r100.xml
xpath: //prf:BitsPerPixel

Appreciate further help on this one :)
0
 
b1xml2Commented:
in such a case,

 <%@Language="VBScript"%>
<%
Dim http
Dim document
Dim namespaces
Dim node
Dim name
Dim xpath

Set http = Server.CreateObject("Msxml2.XMLHTTP")
http.Open "GET", "http://nds.nokia.com/uaprof/N6610r100.xml", False
http.Send

Set document = Server.CreateObject("Msxml2.DOMDocument")
document.async = False
document.validateOnParse = False
document.resolveExternals = False
document.load http.responseBody
         
document.setProperty "SelectionLanguage","XPath"
name = "BitsPerPixel"
xpath = "//*[local-name() = '" & name & "']"

Set node = document.selectSingleNode(xpath)

If Not node Is Nothing Then
     Response.Write node.Text
Else
     Response.Write "empty"
End If

Set document = Nothing
Set http = Nothing
%>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
HasnerAuthor Commented:
This is just great! My problem is solved :)

Now if I may add the bonus question. In those same UAProf's there are <rdf:Bag> containers with <rdf:li>somedata</rdf:li>. How can I parse them?
0
 
b1xml2Commented:
if you are looking at a function, then

 <%@Language="VBScript"%>
<%
Response.Write GetValue("http://nds.nokia.com/uaprof/N6610r100.xml","BitsPerPixel")


Function GetValue(ByVal url, ByVal name)
On Error Resume Next
Dim http
Dim document
Dim namespaces
Dim node
Dim name
Dim xpath

Set http = Server.CreateObject("Msxml2.XMLHTTP")
http.Open "GET", url, False
http.Send

If http.Status <> "200" Then
      GetValue = Nothing
      Exit Function
End If

Set document = Server.CreateObject("Msxml2.DOMDocument")
document.async = False
document.validateOnParse = False
document.resolveExternals = False
document.load http.responseBody

If document.parseError.errorCode <> 0 Then
      GetValue = Nothing
      Exit Function
End If
         
document.setProperty "SelectionLanguage","XPath"
xpath = "//*[local-name() = '" & name & "']"

Set node = document.selectSingleNode(xpath)

If Not node Is Nothing Then
     GetValue = node.Text
Else
     GetValue = Nothing
End If

Set document = Nothing
Set http = Nothing
End Function


%>
0
 
b1xml2Commented:
>>
Now if I may add the bonus question. In those same UAProf's there are <rdf:Bag> containers with <rdf:li>somedata</rdf:li>. How can I parse them?
<<

what node are you looking at??? pls post the xml fragment here...
0
 
HasnerAuthor Commented:
Ok I have tested it and my problem is solved!

Thanks alot :)
0
 
HasnerAuthor Commented:
Just wanted to add one last comment.

If you are using
request.ServerVariables("HTTP_X_WAP_PROFILE") for WAP devices you have to
replace(request.ServerVariables("HTTP_X_WAP_PROFILE"),chr(34),"") to eliminate the " that the servervariables return.

Thanks!
0
 
HasnerAuthor Commented:
Forgot to follow up on my own question regarding parsing <rdf:Bag> data.

Look at this code snippet cut from: http://nds1.nds.nokia.com/uaprof/N6230r200.xml

- <prf:CcppAccept>
- <rdf:Bag>
  <rdf:li>application/vnd.wap.connectivity-wbxml</rdf:li>
  <rdf:li>application/vnd.wap.sic</rdf:li>
  <rdf:li>application/vnd.wap.slc</rdf:li>
  <rdf:li>text/x-vCard</rdf:li>
  <rdf:li>text/x-vCalendar</rdf:li>
  <rdf:li>application/vnd.wap.hashed-certificate</rdf:li>
  <rdf:li>application/vnd.wap.signed-certificate</rdf:li>
  <rdf:li>application/vnd.wap.cert-response</rdf:li>
  <rdf:li>application/x-wap-prov.browser-bookmarks</rdf:li>
  <rdf:li>text/html</rdf:li>
  <rdf:li>text/vnd.wap.wml</rdf:li>
  <rdf:li>application/xhtml+xml</rdf:li>
  <rdf:li>application/vnd.wap.xhtml+xml</rdf:li>
  <rdf:li>application/vnd.oma.dd+xml</rdf:li>
  <rdf:li>application/vnd.oma.drm.message</rdf:li>
  <rdf:li>application/x-wallet-appl.user-data-provision</rdf:li>
  <rdf:li>image/gif</rdf:li>
  <rdf:li>image/jpeg</rdf:li>
  <rdf:li>image/jpg</rdf:li>
  <rdf:li>image/bmp</rdf:li>
  <rdf:li>image/png</rdf:li>
  <rdf:li>image/vnd.wap.wbmp</rdf:li>
  <rdf:li>image/vnd.nok-wallpaper</rdf:li>
  <rdf:li>video/3gpp</rdf:li>
  <rdf:li>audio/3gpp</rdf:li>
  <rdf:li>video/mp4</rdf:li>
  <rdf:li>audio/amr</rdf:li>
  <rdf:li>application/sdp</rdf:li>
  <rdf:li>audio/midi</rdf:li>
  <rdf:li>audio/mid</rdf:li>
  <rdf:li>audio/x-midi</rdf:li>
  <rdf:li>audio/x-mid</rdf:li>
  <rdf:li>audio/sp-midi</rdf:li>
  <rdf:li>application/vnd.nokia.ringing-tone</rdf:li>
  <rdf:li>audio/mpeg</rdf:li>
  <rdf:li>audio/mp4</rdf:li>
  <rdf:li>audio/mpeg4</rdf:li>
  <rdf:li>text/vnd.sun.j2me.app-descriptor</rdf:li>
  <rdf:li>application/vnd.oma.drm.content</rdf:li>
  <rdf:li>application/vnd.met.ticket</rdf:li>
  <rdf:li>application/java</rdf:li>
  <rdf:li>application/vnd.oma.drm.rights+xml</rdf:li>
  <rdf:li>application/vnd.met.receipt</rdf:li>
  <rdf:li>application/java-archive</rdf:li>
  <rdf:li>application/vnd.oma.drm.rights+wbxml</rdf:li>
  <rdf:li>image/vnd.nok-oplogo-color</rdf:li>
  <rdf:li>application/x-java-archive</rdf:li>
  </rdf:Bag>
  </prf:CcppAccept>

What I want is to parse the data from say all items with images/* How can I accomplish that with the above written function?

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now