我有这样的 XML 格式:
<?xml version="1.0" encoding="Windows-1252"?>
<!--MasterMusik Video Database-->
<Videos>
  <Video><Name>SKRILLEX & WOLFGANG GARTNER - THE DEVIL's DEN</Name><Genre>Techno</Genre><Format>mp4</Format><HD>HD</HD><Resolution>1280x720</Resolution><Size>70,57</Size></Video>
  <Video><Name>4 Strings - Let It Rain</Name><Genre>Dance</Genre><Format>mp4</Format><HD>HD</HD><Resolution>1920x1080</Resolution><Size>129,3</Size></Video>
  <Video><Name>Deadmau5 - I Remember (Live At Roskilde Festival)</Name><Genre>Trance</Genre><Format>mkv</Format><HD>SD</HD><Resolution>704x384</Resolution><Size>97,99</Size></Video>
</Videos>
我想按元素的“名称”标签对元素进行排序。
这是我用来对元素排序的函数排序 XML 文档
Private Function XML_Sort(ByVal xdoc As XDocument, _
                          ByVal Root_Element As String, _
                          ByVal Element_to_sort As String) As XDocument
    Try
        xdoc.Root.ReplaceNodes(xdoc.Root.Elements(Root_Element) _
                              .OrderBy(Function(sort) sort.Element(Element_to_sort).Value))
        Return xdoc
    Catch ex As Exception
        Throw New Exception(ex.Message)
    End Try
End Function
但是我得到的输出是完全缩进的:
<!--MasterMusik Video Database-->
<Videos>
  <Video>
    <Name>4 Strings - Let It Rain</Name>
    <Genre>Dance</Genre>
    <Format>mp4</Format>
    <HD>HD</HD>
    <Resolution>1920x1080</Resolution>
    <Size>129,3</Size>
  </Video>
  <Video>
    <Name>Deadmau5 - I Remember (Live At Roskilde Festival)</Name>
    <Genre>Trance</Genre>
    <Format>mkv</Format>
    <HD>SD</HD>
    <Resolution>704x384</Resolution>
    <Size>97,99</Size>
  </Video>
  <Video>
    <Name>SKRILLEX & WOLFGANG GARTNER - THE DEVIL's DEN</Name>
    <Genre>Techno</Genre>
    <Format>mp4</Format>
    <HD>HD</HD>
    <Resolution>1280x720</Resolution>
    <Size>70,57</Size>
  </Video>
</Videos>
这是我正在使用的用法:
Dim xdoc As XDocument = _
    XDocument.Load("Videos.xml", LoadOptions.PreserveWhitespace)
xdoc = XML_Sort(xdoc, "Video", "Name")
IO.File.WriteAllText("Sorted Videox.xml", xdoc.ToString)
此时有两个问题:
- 输出是缩进的。 
- XML的声明没有写 - <?xml version="1.0" encoding="Windows-1252"?>,需要自己手动写。
我怎样才能解决这两个问题?