Solved

Parse XML with xmldom

Posted on 2004-09-01
11
640 Views
Last Modified: 2012-08-14
I'm using xmldom to parse an xml page.
There are the first few line of the xml doc.

xml doc:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91">

My problem is when I load the xml doc, if the <!DOCTYPE > line is present like seen above I get and error (msxml3.dll error '8000000a' ) and I can read the rest of the document.

However, if I take the <!DOCTYPE > line out every thing works fine

Is there a way to delete is Line before I parse the information?
I would perfer not to replace the line because the Line might change.
0
Comment
Question by:quest_capital
  • 6
  • 5
11 Comments
 
LVL 4

Expert Comment

by:chipple
ID: 11960628
You're using ASP?
I would use a regular expression to remove the DOCTYPE.

Dim xml
' Your XML text is in this variable

Dim rx
Set rx = New RegExp
rx.Pattern = "<!DOCTYPE[^>]*>"
xml = rx.Replace(xml,"")
Set rx = Nothing

' DOCTYPE line has been removed

(Code provided not tested.)

Good luck!
0
 
LVL 4

Expert Comment

by:chipple
ID: 11960644
If you also want to get rid of the line break after the doctype line, use this pattern instead:
rx.Pattern = "<!DOCTYPE[^>]*>[" & vbCrLf & "]+"
0
 

Author Comment

by:quest_capital
ID: 11962775
chipple

I tried the  code and it did not work I got a code mismatch here is the code:

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  xml.Open "GET", "http://www.feedroom.com/rssout/national_rss_9a50890a7af8c2150f8bb6af03d6264a8fa88134.xml", False
 ' xml.Open "GET", "http://www.questentertainmentgroup.com/uploads/moreover.xmlhouston_news.xml", False

  ' Actually Sends the request and returns the data:
  xml.Send
 
'Dim xml
' Your XML text is in this variable
Dim rx
Set rx = New RegExp
rx.Pattern = "<!DOCTYPE[^>]*>"
xml = rx.Replace(xml,"") '............................Type Mismatch Here................................
Set rx = Nothing
' DOCTYPE line has been removed

Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Path = Server.MapPath("/uploads/")
FullPath = Path & "\Feed.xml"

Set objTF = objFSO.CreateTextFile(FullPath,True)
objTF.Write xml.ResponseText

  'Display the HTML both as HTML and as text
  Response.Write "<xmp>"
  Response.Write xml.responseText
 
  Set xml = Nothing
%>
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:quest_capital
ID: 11962805
The Code above brings the xml down to local server.
The Cade below parses the xml.

Maybe I have the code in the wrong place?????????????????

<%
Dim objXML, elements, i, url, Headline, Place, tTime, title
'Set objXML = Server.CreateObject("Msxml2.DomDocument")
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.validateOnParse="false"
objXML.async="false"
objXML.Load (Server.MapPath("\uploads\Feed.xml"))
'objXML.Load (Server.MapPath("\uploads\moreover.xmlhouston_news.xml"))
'objXML.removeChild(pubDate)

'4) Capture of number of links
IF Request.QueryString("num")= "" Then
NumberOfLinks = 2
Else
NumberOfLinks = 15
End IF

'if there are no errors
If objXML.parseError.errorcode = 0 Then

'Set Root = objXML.documentElement
Set elements = objXML.getElementsByTagName("item")  
'Set elements = objXML.getElementsByTagName("article")

For i = 1 to NumberOfLinks
'for each elem in elements
'For i = 0 to (elements.length - 25)
'For i = 0 to (elements.+4)

title = elements.item(i).childNodes(0).Text
'Headline = elements.item(i).childNodes(1).Text
'Place = elements.item(i).childNodes(2).Text
'tTime = elements.item(i).childNodes(7).Text
Response.Write("" & title & "")
'Response.Write("" & url & "")
'Response.Write("<a href=" & URL & " target=_blank ><strong>"& Headline &"</strong></a>"&"<br>")
'Response.Write(Place & "  "& tTime & "<br>"& "<br>")
Next
Set objXML = Nothing

Else
Response.Write ("There was an error")
End If
%>
0
 
LVL 4

Expert Comment

by:chipple
ID: 11962848
Try this. The Replace method needs text but you were giving it your XMLHTTP object.

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  xml.Open "GET", "http://www.feedroom.com/rssout/national_rss_9a50890a7af8c2150f8bb6af03d6264a8fa88134.xml", False
 ' xml.Open "GET", "http://www.questentertainmentgroup.com/uploads/moreover.xmlhouston_news.xml", False

  ' Actually Sends the request and returns the data:
  xml.Send
 
'Dim xml
' Your XML text is in this variable
Dim rx
Set rx = New RegExp
rx.Pattern = "<!DOCTYPE[^>]*>"
xml = rx.Replace(xml.xml,"")
Set rx = Nothing
' DOCTYPE line has been removed

Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Path = Server.MapPath("/uploads/")
FullPath = Path & "\Feed.xml"

Set objTF = objFSO.CreateTextFile(FullPath,True)
objTF.Write xml.ResponseText

  'Display the HTML both as HTML and as text
  Response.Write "<xmp>"
  Response.Write xml.responseText
 
  Set xml = Nothing
%>
0
 

Author Comment

by:quest_capital
ID: 11963232
chipple

I got an object doesn't support this property or method 'xml' error
on the same line.
0
 
LVL 4

Expert Comment

by:chipple
ID: 11963303
Sorry about that, please try xml.responseText instead of xml.xml. I was confused with something else.

<%
  Response.Buffer = True
  Dim objXMLHTTP, xml

  ' Create an xmlhttp object:
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")
  ' Or, for version 3.0 of XMLHTTP, use:
  ' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

  ' Opens the connection to the remote server.
  xml.Open "GET", "http://www.feedroom.com/rssout/national_rss_9a50890a7af8c2150f8bb6af03d6264a8fa88134.xml", False
 ' xml.Open "GET", "http://www.questentertainmentgroup.com/uploads/moreover.xmlhouston_news.xml", False

  ' Actually Sends the request and returns the data:
  xml.Send
 
'Dim xml
' Your XML text is in this variable
Dim rx
Set rx = New RegExp
rx.Pattern = "<!DOCTYPE[^>]*>"
xml = rx.Replace(xml.responseText,"")
Set rx = Nothing
' DOCTYPE line has been removed

Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Path = Server.MapPath("/uploads/")
FullPath = Path & "\Feed.xml"

Set objTF = objFSO.CreateTextFile(FullPath,True)
objTF.Write xml.ResponseText

  'Display the HTML both as HTML and as text
  Response.Write "<xmp>"
  Response.Write xml.responseText
 
  Set xml = Nothing
%>
0
 

Author Comment

by:quest_capital
ID: 11964398
Wel I would love to try the code but the server want update to the newest page. That happens from time to time I think I will add anther post for it.
0
 

Author Comment

by:quest_capital
ID: 11969117
chipple

I get a blank xml document and is error below:

Microsoft VBScript runtime error '800a01a8'
Object required: 'objTF'
/uploads/maptest2.asp, line 35

on this code:
Set objTF = objFSO.CreateTextFile(FullPath,True)
objTF.Write xml.ResponseText

0
 
LVL 4

Accepted Solution

by:
chipple earned 500 total points
ID: 11969979
Ok actually you had just put my piece of code in the middle of your script without altering the rest in consequence.
Let me try to fix this.

<%
Response.Buffer = True
Dim objXMLHTTP, xml

' Create an xmlhttp object:
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
' Or, for version 3.0 of XMLHTTP, use:
' Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

' Opens the connection to the remote server.
xml.Open "GET", "http://www.feedroom.com/rssout/national_rss_9a50890a7af8c2150f8bb6af03d6264a8fa88134.xml", False
' xml.Open "GET", "http://www.questentertainmentgroup.com/uploads/moreover.xmlhouston_news.xml", False

' Actually Sends the request and returns the data:
xml.Send
 
'Remove DOCTYPE
Dim rx
Set rx = New RegExp
rx.Pattern = "<!DOCTYPE[^>]*>"
Dim xmlNoDoctype
xmlNoDoctype = rx.Replace(xml.responseText,"")
Set rx = Nothing

Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Path = Server.MapPath("/uploads/")
FullPath = Path & "\Feed.xml"

Set objTF = objFSO.CreateTextFile(FullPath,True)
objTF.Write xmlNoDoctype

'Display the HTML both as HTML and as text
Response.Write "<xmp>"
Response.Write xmlNoDoctype
 
Set xml = Nothing
%>
0
 

Author Comment

by:quest_capital
ID: 11996299
Thank Chipple

That worked out great. Please check for my next post.
I want to automatically download this xml page every hour.
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21121423.html
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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