Parsing XML with ASP

前端 未结 2 2098
感情败类
感情败类 2021-01-27 11:41

I have the code below, I just need help on figuring out the best way to get html from the content node below instead of plaintext. Any help is much appreciated.



        
2条回答
  •  花落未央
    2021-01-27 12:33

    In my experience the best way of handling XML with Classic ASP is to use an XSL stylesheet.

    XSLT is quite easy to learn at a basic level, although the learning curve gets a bit steeper later on.

    I recommend the w3schools tutorial

    http://www.w3schools.com/xsl/

    Once you've written your stylesheet, if you have a local XML source your asp code would look like this

    set xml = Server.CreateObject("Msxml2.DomDocument")
    xml.load(Server.Mappath("source.xml"))
    set xsl = Server.CreateObject("Msxml2.DomDocument")
    xsl.load(Server.Mappath("stylesheet.xsl"))
    Response.Write(xml.transformNode(xsl))
    set xsl = nothing
    set xml = nothing
    

    If the xml is from a remote url then it's a little more complex

    set xml = Server.CreateObject("Msxml2.DomDocument")
    xml.setProperty "ServerHTTPRequest", true
    xml.async = false
    xml.validateOnParse = false
    xml.load("http://xmlsource.com")
    set xsl = Server.CreateObject("Msxml2.DomDocument")
    xsl.load(Server.Mappath("stylesheet.xsl"))
    Response.Write(xml.transformNode(xsl))
    set xsl = nothing
    set xml = nothing
    

    Edit

    <%= Title %>

提交回复
热议问题