我有以下VB.NET代码,并且期望将combobox1的内容写入xml文件,但它什么都没有?
for (Map.Entry<String, Map<String, String>> entryOne : idAndTags.entrySet()) {
shufTags = new HashMap<String, String>();
Map<String, String> tags = entryOne.getValue();
System.out.println(tags);
final List<String> vs = new ArrayList<String>(tags.values());
Collections.shuffle(vs);
final Iterator<String> vIter = vs.iterator();
for (String k : tags.keySet())
shufTags.put(k, vIter.next());
System.out.println(shufTags);
}
答案 0 :(得分:0)
ComboBox1.SelectedText
代表突出显示的内容。执行代码时,可能没有突出显示的蓝色项目。因此,CLIENTID
标签中没有插入任何内容。
使用Combobox1.Text
代替您选择的内容。
.WriteElementString("CLIENTID", ComboBox1.Text)
答案 1 :(得分:0)
我修改了组合框和文本框中的代码硬编码值。然后我将结果放入DataGridView,它似乎工作。
Imports System.Xml
Public Class Form1
Const FILENAME As String = "c:\temp\test.xml"
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim objWriter As New System.IO.StreamWriter(FILENAME)
objWriter.WriteLine("<COMPELATION>")
objWriter.WriteLine("</COMPELATION>")
objWriter.Close()
'Writing XML content...
Dim xmldoc As XmlDocument = New XmlDocument()
xmldoc.Load(FILENAME)
With xmldoc.SelectSingleNode("/COMPELATION").CreateNavigator().AppendChild()
.WriteStartElement("DATA")
.WriteElementString("PROJECTID", "abc")
.WriteElementString("CLIENTID", "def")
.WriteElementString("CDATE", Date.Today)
.WriteElementString("CTIME", Now.ToShortTimeString)
.WriteEndElement()
.Close()
End With
xmldoc.Save(FILENAME)
Dim filepath As String = (FILENAME)
Dim DS_PROJECTS As New DataSet
DS_PROJECTS.ReadXml(filepath)
DataGridView1.DataSource = DS_PROJECTS.Tables(0)
End Sub
End Class