ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 4th, 2009, 01:29 AM
SteveShipton SteveShipton is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 SteveShipton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 32 sec
Reputation Power: 0
Unhappy VBScript - General - Question - Problems Parsing XML from an HTTP response

Hi!

I have written a block of code in .asp to pull an xml file from a customers site using Msxml2.ServerXMLHTTP.4.0, which then passes the .responseBody straight into a microsoft.XMLDOM object

set Nlv_Http = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
Nlv_Http.open "GET", Nqv_XMLImportFile, false
Nlv_Http.Send ""

if (Nlv_Http.status <> 200 ) then
' deal with the error
else
Set Nlv_XML = Server.CreateObject("microsoft.XMLDOM")
Nlv_XML.async = False
Nlv_XML.validateOnParse = False
Nlv_XML.load(Nlv_Http.responseBody)

if Nlv_XML.parseError.errorCode = 0 then
......

which is working fine for 99% of feeds but I get errors with the ' character. I assumed that if I put the response straight into the load that the encoding would remain the same as the feed. The offending feed is UTF-8.

Any help would be appreciated...

Would also be happy if somebody called me stupid and pointed out a simple error

Reply With Quote
  #2  
Old November 4th, 2009, 03:06 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Hi and welcome to the forums!

If you are facing problems because of single quote then you can replace it. Something like
Code:
Replace(strInput, "'", "&apos;")


Generally xml can break or have problems with &, <, >, " and '
So i make a function like this
Code:
Function chkCharacters(strInput)
        'Replace special characters from xml
        strInput = Replace(strInput, "&", "&")
        strInput = Replace(strInput, """", """)
        strInput = Replace(strInput, "<", "<")
        strInput = Replace(strInput, ">", ">")
        strInput = Replace(strInput, "'", "&apos;")

        chkCharacters = strInput
End Function
__________________
Laziness is my religion and Sunday is my God

Get the Mantra!

Reply With Quote
  #3  
Old November 4th, 2009, 03:21 AM
SteveShipton SteveShipton is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 SteveShipton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 32 sec
Reputation Power: 0
Hi Micky, Thanks for the reply!

Are you saying that i should change line my line to:

Nlv_XML.load(ReplaceFunction(Nlv_Http.responseBody ))

Will this preseve the encoding from the stream?

Steve


Quote:
Originally Posted by micky
Hi and welcome to the forums!

If you are facing problems because of single quote then you can replace it. Something like
Code:
Replace(strInput, "'", "&apos;")


Generally xml can break or have problems with &, <, >, " and '
So i make a function like this
Code:
Function chkCharacters(strInput)
        'Replace special characters from xml
        strInput = Replace(strInput, "&", "&")
        strInput = Replace(strInput, """", """)
        strInput = Replace(strInput, "<", "<")
        strInput = Replace(strInput, ">", ">")
        strInput = Replace(strInput, "'", "&apos;")

        chkCharacters = strInput
End Function

Reply With Quote
  #4  
Old November 4th, 2009, 03:28 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Well, you can try it and see if it works

Reply With Quote
  #5  
Old November 4th, 2009, 04:04 AM
SteveShipton SteveShipton is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 3 SteveShipton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 32 sec
Reputation Power: 0
Hi Micky,

I think it is actually my customer who has encoded their stream incorrectly; spent many hours looking at what they are sending and it looks as though they have not encoded text in one tag in the same way as they have in another; lots of cutting and pasting in a 4MB XML file and it now works.

BTW using replace on the HTTP response stream did not work as Replace didn't like a stream as imput.

Thanks for the quick responses.

Steve

Quote:
Originally Posted by micky
Well, you can try it and see if it works

Reply With Quote
  #6  
Old November 4th, 2009, 04:20 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Glad you got it working.

I also wasnt sure about Replace.......... anyway, thanx for sharing the solution

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > VBScript - General - Question - Problems Parsing XML from an HTTP response


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek