Solved

Parse XML with xmldom

Posted on 2004-09-01
11
639 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now