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
  • 相关阅读:
    数学之矩阵快速幂
    数学篇之高斯消元
    P1033自由落体
    P1258小车问题
    P1072Hankson的趣味题
    P2837晚餐队列安排
    P3811 乘法逆元
    P1002过河卒
    P1507 NASA的食物计划
    P1079 Vigenère 密码
  • 原文地址:https://www.cnblogs.com/yhsc/p/4393674.html
Copyright © 2011-2022 走看看