XML newbie question - spot the difference

Discussion in 'XML' started by blingk, Jan 13, 2008.

  1. blingk

    blingk Guest

    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?wci=results&xslt=-1&eaid=639&perpage=32000&showstc=on

    ....and here to see it for the featured properties results...
    http://www.dezrez.com/webservices/featured/featuredProperty.aspx?eaid=639&number=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??)
     
    blingk, Jan 13, 2008
    #1
    1. Advertising

  2. 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?wci=results&xslt=-1&eaid=639&perpage=32000&showstc=on
    >
    > ...and here to see it for the featured properties results...
    > http://www.dezrez.com/webservices/featured/featuredProperty.aspx?eaid=639&number=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/
     
    Martin Honnen, Jan 13, 2008
    #2
    1. Advertising

  3. blingk

    blingk Guest

    > 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/featured/featuredProperty.aspx?eaid=639&number=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"
    xmlns:xsl="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?
     
    blingk, Jan 13, 2008
    #3
  4. blingk

    blingk Guest

    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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput 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."
     
    blingk, Jan 14, 2008
    #4
  5. 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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    > <xsl:eek:utput 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/
     
    Martin Honnen, Jan 14, 2008
    #5
  6. blingk

    blingk Guest

    On Jan 14, 12:51 pm, Martin Honnen <> 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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > > version="1.0">
    > > <xsl:eek:utput 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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput 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).
     
    blingk, Jan 14, 2008
    #6
  7. 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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    > <xsl:eek:utput 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/
     
    Martin Honnen, Jan 14, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A great onestop spot

    , Feb 7, 2006, in forum: Perl
    Replies:
    0
    Views:
    2,076
  2. PerlBoy

    hot spot

    PerlBoy, Feb 22, 2006, in forum: HTML
    Replies:
    1
    Views:
    534
    Disco Octopus
    Feb 22, 2006
  3. urocrane

    spot the bug

    urocrane, Jul 12, 2003, in forum: C++
    Replies:
    3
    Views:
    436
    John Carson
    Jul 12, 2003
  4. JKop
    Replies:
    3
    Views:
    443
    Old Wolf
    Oct 13, 2004
  5. Andreas Vinther

    Please help me spot the difference

    Andreas Vinther, Oct 23, 2006, in forum: C Programming
    Replies:
    9
    Views:
    424
    Andreas Vinther
    Nov 6, 2006
Loading...

Share This Page