Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML newbie question - spot the difference

Reply
Thread Tools

XML newbie question - spot the difference

 
 
blingk
Guest
Posts: n/a
 
      01-13-2008
I'm an XML newbie trying to add a property search and a featured
property to an estate agent's website using various XML bits sent to
me by the people who host their properties (a company called Dezrez).

Click here to see what the XML returned looks like for the property
search results...
http://data.dezrez.com/search.asp?wc...000&showstc=on

....and here to see it for the featured properties results...
http://www.dezrez.com/webservices/fe...r=3&;showxml=1

Is this latter XML formed properly? The first one is recognized as XML
by the browser but the second seems to be interpreted as a web page
(which might be why I am getting no results when running this through
XSL or XSLT files??)
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-13-2008
blingk wrote:
> I'm an XML newbie trying to add a property search and a featured
> property to an estate agent's website using various XML bits sent to
> me by the people who host their properties (a company called Dezrez).
>
> Click here to see what the XML returned looks like for the property
> search results...
> http://data.dezrez.com/search.asp?wc...000&showstc=on
>
> ...and here to see it for the featured properties results...
> http://www.dezrez.com/webservices/fe...r=3&;showxml=1
>
> Is this latter XML formed properly? The first one is recognized as XML
> by the browser but the second seems to be interpreted as a web page
> (which might be why I am getting no results when running this through
> XSL or XSLT files??)


It is not a problem with the XML contents but rather a question of the
HTTP header the contents is served with. For the first URL it is
text/xml, for the second it is text/html. If you want to serve XML with
ASP then make sure your code sets e.g.
Response.ContentType = "application/xml"
or
Response.ContentType = "text/xml"
before your page sends any contents to the client.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
blingk
Guest
Posts: n/a
 
      01-13-2008
> It is not a problem with the XML contents but rather a question of the
> HTTP header the contents is served with. For the first URL it is
> text/xml, for the second it is text/html. If you want to serve XML with
> ASP then make sure your code sets e.g.
> Response.ContentType = "application/xml"
> or
> Response.ContentType = "text/xml"
> before your page sends any contents to the client.


Ok thanks for that, gets me a bit closer.

I'm still struggling to get this working though. I've got 2 tests on
the go, both using the results from...
http://www.dezrez.com/webservices/fe...er=3&showxml=1
(slightly corrupted in my original message).

**** Test 1: Files are features2.asp & test.xsl ****

---test.xsl---

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>TEST</h2>
<table border="1">
<xsl:for-each select="properties/property">
<tr>
<td><xsl:value-of select="price" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>



--featured2.asp---

<%
Response.ContentType = "text/xml"

dim sLink
dim xslt
dim oHttpRequest
dim outputHTML

sLink = "http://www.dezrez.com/webservices/featured/
featuredProperty.aspx?eaid=639&number=3&showxml=1"

'response.write(sLink)
'xml request objects
'Load XML

Set XML = Server.CreateObject("Microsoft.XMLDOM")
set xmlhttp=createObject("Microsoft.XMLHTTP")
xmlhttp.onreadystatechange=getRef("stateChange")
xmlhttp.Open "POST", sLink, false
xmlhttp.Send()

'dim blah
'blah = xmlhttp.responseText

'XML received
function stateChange()


dim num
if xmlhttp.readyState=4 then
if xmlhttp.status=200 then
xml.load (xmlhttp.responseXML)

'load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("test.xsl"))

'Transform file
outputHTML = xml.transformNode(xsl)
else
Response.Write("XML data not OK")
Response.Write(xmlhttp.responseXML)
end if
end if


end function
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<%
Response.write(outputHTML)
'Response.write(blah)
%>
</body>
</html>


Result = just the heading TEST


What am I doing wrong here?
 
Reply With Quote
 
blingk
Guest
Posts: n/a
 
      01-14-2008
My other test, using an XSLT file currently looks like this...

Files - featured.asp & searchresults4.xslt

---- searchresults4.xslt ----

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="html"/>
<xsl:template match="/">
<xsl:value-of select select="count(properties/property)"/>
</xsl:template>
</xsl:stylesheet>


The idea is that as a basic test we just count the number of property
nodes.


---- featured.asp ----

Exactly as posted previously but pointed at the xslt file above...

xsl.load(Server.MapPath("searchresults4.xslt"))


---- Result: "The stylesheet does not contain a document element. The
stylesheet may be empty, or it may not be a well-formed XML document."
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      01-14-2008
blingk wrote:
> My other test, using an XSLT file currently looks like this...
>
> Files - featured.asp & searchresults4.xslt
>
> ---- searchresults4.xslt ----
>
> <?xml version="1.0" encoding="windows-1252" ?>
> <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xslutput method="html"/>
> <xsl:template match="/">
> <xsl:value-of select select="count(properties/property)"/>

^^^^^^^^
That is not well-formed XML.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
blingk
Guest
Posts: n/a
 
      01-14-2008
On Jan 14, 12:51 pm, Martin Honnen <(E-Mail Removed)> wrote:
> blingk wrote:
> > My other test, using an XSLT file currently looks like this...

>
> > Files - featured.asp & searchresults4.xslt

>
> > ---- searchresults4.xslt ----

>
> > <?xml version="1.0" encoding="windows-1252" ?>
> > <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0">
> > <xslutput method="html"/>
> > <xsl:template match="/">
> > <xsl:value-of select select="count(properties/property)"/>

>
> ^^^^^^^^
> That is not well-formed XML.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/



Yes, thanks, well spotted. Fixing this line stops the errors, but
isn't returning the right result. If you look at the XML file, there
are 3 featured properties. The result I now get is '0'.

Still something I'm doing wrong here obviously. As a test I tried
changing the XSLT to...

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="properties"/>
</xsl:template>
<xsl:template match="properties">
<xsl:for-each select="property">
<div>
<xsl:value-of select="description1"/>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

....in case the count method was being used wrongly somehow. The result
of the above is a blank page (as if there are no results).
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      01-14-2008
blingk wrote:

> Still something I'm doing wrong here obviously. As a test I tried
> changing the XSLT to...
>
> <?xml version="1.0" encoding="windows-1252" ?>
> <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xslutput method="html"/>
> <xsl:template match="/">
> <xsl:apply-templates select="properties"/>
> </xsl:template>
> <xsl:template match="properties">
> <xsl:for-each select="property">
> <div>
> <xsl:value-of select="description1"/>


The XML sample is long and poorly formatted for human reading but it
looks as if the child element name is 'description' and not
'description1' so you need
<xsl:value-of select="description"/>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me spot the difference Andreas Vinther C Programming 9 11-06-2006 10:53 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Spot the difference Max NZ Computing 6 11-10-2005 08:45 AM
Last 10D question: How big a deal is no spot metering? Paul Digital Photography 16 09-26-2003 10:13 PM



Advertisments