【问题标题】:Combine several strings into one xml document vb.net将多个字符串组合成一个 xml 文档 vb.net
【发布时间】:2012-01-17 00:29:23
【问题描述】:

我正在尝试将包含多个字典值的多个字符串写入单个 XML 文件。最好的方法是什么?我认为 xDocument 看起来是最好的方法,但我正在努力将多个字符串写入一个文档。

我打算从这个 XML 文件中读取,所以它必须是有效的。

【问题讨论】:

    标签: xml vb.net string dictionary


    【解决方案1】:

    如果我不理解您的问题,请原谅,但您不能只添加一个父元素 " 来包含所有字符串吗?

    Dim sbUser As New System.Text.StringBuilder
    sbUser.AppendLine("<?xml version=""1.0""?>")
    sbUser.AppendLine("<root>")
    sbUser.AppendLine("<services>")
    For Each item As KeyValuePair(Of Integer, Users) In dictusers
        sbUser.AppendFormat("<Name>""{0}""<SessionID>""{1}""</SessionID><UserName>{2}</UserName></Name>", item.Key, item.Value.SessionID, item.Value.UserName).AppendLine()
    Next
    sbUser.AppendLine("</services>")
    sbUser.AppendLine("<cpus>")
      ...
    sbUser.AppendLine("</cpus>")
      ...
    sbUser.AppendLine("</root>")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-25
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      相关资源
      最近更新 更多