Use XSLT to change the XML root

Source: Internet
Author: User
Tags xsl xsl file xslt
It is inconvenient to change the XML root for writing a program. Therefore, I wrote a function. the general idea and implementation of this function are as follows: first, I felt that I could filter something using XSLT and then send it back to the client, so I decided to use XSLT and then try to write a root change.

It is inconvenient to change the XML root for writing a program. Therefore, I wrote a function. the general idea and implementation are as follows:

First, I felt that I could filter something using XSLT and send it back to the client. so I decided to use XSLT.

Then try to write an XSL for root replacement, as shown below:

Reference content is as follows:












The general meaning is to parse all nodes and attributes in an XML file. if it is not the root, copy them directly; otherwise, check whether there are child nodes and attributes. For more information, see The SDK documentation of MSXML.

Then write a function so that NEWNODENAME can specify:

This code is implemented in VB. Net. in ASP, you need to pay attention to the use of Set for object values and the title of returned values.

Reference content is as follows:

Public Function ChangeXmlRootNodeName (ByRef oXml As MSXML2.DOMDocument, ByVal name As String) As String
If oXml Is Nothing Then
Return ""
End If
Dim sXslt As String
SXslt =" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt & vbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt & "<" & name & ">" & vbCrLf"
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt & vbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "& VbCrLf
SXslt = sXslt &" "" & VbCrLf"
SXslt = sXslt &" "" & VbCrLf"
SXslt = sXslt & vbCrLf
SXslt = sXslt &" "& VbCrLf

Dim oXsl As New MSXML2.DOMDocument
OXsl. async = False
OXsl. resolveExternals = False
OXsl. loadXML (sXslt)

Dim sXml As String

SXml = oXml. transformNode (oXsl)

SXml = AddXmlHeader (sXml)

SXsl = Nothing

Return sXml
End Function

Also, of course, you can also implement the XSL file generated by the native XSL, which depends on how you design it.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.