SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml-xsl-asp -special/reserved character like <br> &

    I am using ASP XML AND XSL also I am very new to xml/xsl. I was given about 1000 xml files to be display on my asp. my xml files contains html character like <br>, &...I keep getting errors bec' of the special characters. How can I handle the special character?

    ------ my mxl files looks simelar to this (same structure)
    <?xml version="1.0" encoding="iso-8859-1"?>
    <FOLDER>
    <folder-name>Addictions</folder-name>
    <category>
    <category-name>Articles</category-name>
    <category-items>
    <item-name>Article ..more & blah blah..<br></item-name>
    <item-description>Articleblah blah..<br></item-description>
    <item-id>1100</item-id>
    </category-items>

    <category-items>
    <item-name>More More blahh</item-name>
    <item-description>Articlemmmmmmm</item-description>
    <item-id>1001</item-id>
    </category-items>
    </category>

    <category>
    <category-name>FAQ</category-name>
    <category-items>
    <item-name>FQA blahh blahh.</item-name>
    <item-description>more.</item-description>
    <item-id>1101</item-id>
    </category-items>
    <category-items>
    <item-name>blahh blahh...<br></item-name>
    <item-description>more..<br></item-description>
    <item-id>1022</item-id>
    </category-items>
    </category>
    </folder>
    </DATAAREA>
    </FOLDER>

    ----------XSL FILE ----------
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/Transform">
    <xslaram name="strCategory"/>
    <xsl:template match="category">

    <xsl:if test="category-name = $strCategory">
    <div><xsl:value-of select="child::category-name"/></div>
    <xsl:for-each select="category-items">
    <div><xsl:variable name="itemid">
    <xsl:apply-templates select="child::item-id"/>

    </xsl:variable>
    <xsl:variable name="itemdescription">
    <xsl:apply-templates select="child::item-description"/>
    </xsl:variable>

    <a title="{$itemdescription}" href="../advocate/itmes/{$itemid}-07-Jan-2005.xml"><xsl:apply-templates select="child::item-name"/> </a></div> <div><xsl:apply-templates select="child::item-description"/>
    </div>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    --------asp file---------
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    function showxmldata(strMXLFile, strXSLFile, strParam)
    dim blnXMLOK
    dim blnXSLOK
    dim strFilesErr


    Set xmlDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
    Set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
    'xmlDoc.preserveWhiteSpace = true
    blnXMLOK = xmlDoc.load(Server.MapPath(strMXLFile))
    blnXSLOK = xslDoc.load(Server.MapPath(strXSLFile))

    if blnXMLOK and blnXSLOK then
    'check for parameter
    if strParam <> "" then
    set xslt = Server.CreateObject("MSXML2.XSLTemplate")
    set xslt.stylesheet = xslDoc
    Set xslProc = xslt.createProcessor()
    xslProc.input = xmlDoc
    xslProc.addParameter "strCategory", cstr(strParam)
    xslProc.transform
    sOutput = xslProc.output
    response.Write(sOutput)
    set xslProc = nothing
    set xslt = nothing

    else
    response.Write(xmlDoc.transformNode(xslDoc))

    end if


    else
    if not blnXMLOK then
    strFileErr = strFileErr & "strXMLFile: " & strMXLFile
    end if
    if not blnXSLOK then
    strFileErr = "<br>" & strFileErr & "strXSLFile: " & strXSLFile
    end if
    'DisplayError(strFileErr)
    End if

    set xmlDoc = nothing
    set xslDoc = nothing

    End Function

    %>
    <html>
    <HEAD>
    </HEAD>

    <BODY>
    <%
    Dim strMXLFile, strXSLFile, strParam

    vMXLFile = "Addictions.xml"
    vXSLFile = "Additions.xsl"
    vParam = "Articles"
    %>

    <table>
    <tr>
    <td>
    <% showxmldata vMXLFile, vXSLFile, vParam %>
    </td>
    </tr>
    </table>
    </BODY>
    </html>

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    XML has to be well-formed. If you have <br> in your XML document it's not well-formed and it's not XML. You can't use XML parsers on documents that aren't XML . If the breaks need to be there, they should be replaced with <br/>, which is self-closing and well-formed XML.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •