zoukankan      html  css  js  c++  java
  • Vb.Net Xml文档格式化

    最近在处理Webservice文档的时候,因为是未格式化的,需要处理,所以有了以下代码。

    #Region "Xml字符串转换成格式化的XML文件"
    
        
        'txt_Result.Text = StrToXml(txt_Result.Text)
    
        Public Function StrToXml(ByVal strTmp As String) As String
    
            'XmlDocument可以从文件加载,也可以从字符串、数据流加载
    
            Dim Doc As New XmlDocument
            Dim strPath As String
    
            Dim MStream As New MemoryStream(1024)
            Dim XmlWriter As New XmlTextWriter(MStream, Nothing)
            Dim encoding As Encoding
    
            strPath = System.Windows.Forms.Application.StartupPath & "XmlTemp.xml"
    
            '从字符串读取
            Doc.LoadXml(strTmp)
            Doc.Save(strPath)
    
            XmlWriter.Formatting = Formatting.Indented
    
            Doc.Load(strPath)
            Doc.WriteTo(XmlWriter)
            XmlWriter.Flush()
            XmlWriter.Close()
            encoding = System.Text.Encoding.GetEncoding("utf-8")
            strTmp = encoding.GetString(MStream.ToArray())
            MStream.Close()
            StrToXml = strTmp
    
        End Function
    
    #End Region
  • 相关阅读:
    2015年中国500强企业
    汇编语言
    oracle数据库学习路线
    OI生涯回忆录
    NOIP 2020游记
    CF223B Two Strings 题解
    CSP-S 2020游记
    CSP/NOIP 注意事项(2020)
    Luogu P6583 回首过去 题解
    Luogu P2210 Haywire 题解
  • 原文地址:https://www.cnblogs.com/yhsc/p/4393674.html
Copyright © 2011-2022 走看看