Parsing XML with ASP

前端 未结 2 2094
感情败类
感情败类 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

    <h2><%= Title %></h2>
    
    0 讨论(0)
  • 2021-01-27 12:39

    You can get the XML of a node using the xml property instead of the text property you are using now:

        dim o_xml, o_node
        set o_xml = Server.CreateObject("Msxml2.DomDocument")
        o_xml.load("books.xml")
        set o_node = o_xml.selectSingleNode("//catalog/book[@id='bk102']")
        Response.Write Server.htmlEncode(o_node.xml)
    

    Docs here: http://msdn.microsoft.com/en-us/library/ms755989%28v=vs.85%29.aspx

    0 讨论(0)
提交回复
热议问题