码迷,mamicode.com
首页 > Web开发 > 详细

Vb.Net Xml文档格式化

时间:2015-04-05 10:23:05      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

最近在处理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

 

Vb.Net Xml文档格式化

标签:

原文地址:http://www.cnblogs.com/yhsc/p/4393674.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!