Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parse XML with xmldom

Posted on 2004-09-01
11
Medium Priority
?
645 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
Industry Leaders: 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!

 

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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

886 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