如何在WPF VB中向XML文件添加新的子集条目? [英] How do I add a new subset entry to an XML file in WPF VB?
问题描述
我有一个XAML文档,其中包含多个客户名称和联系人数据的文本框(即地址,电话,传真,联系人姓名,电子邮件地址)。我有一个sub来检查绑定的xml文档,看看客户名是否已经存在,如果没有,它会为所有文本框创建一个新条目。至少这是个主意。我知道必须有一种方法可以一举将所有XMLElements附加到源代码,但我似乎无法弄清楚如何简化此事件。我想要包括所有缩进和XML验证。
XML数据就这样形成......
<? xml < span class =code-summarycomment> version = 1.0 编码 = utf-8 ? >
< CustDB xmlns :xsi = http://www.w3.org/2001/XMLSchema-instance >
< 客户 >
< 名称 > < / Name >
< 地址1 > < / Address1 >
< 地址2 > < ; / Address2 >
< 电话 > < / Phone >
< 传真 > < / Fax >
< 单元格 > < / Cell >
< 其他 > < span class =code-keyword>< / Other >
< Attn &g t; < / Attn >
< 电子邮件 > ; < / Email >
< SalesPerson > < / SalesPerson >
< / Customer >
< / CustDB >
你好,
L inq to XML。
http:// msdn .microsoft.com / zh-CN / library / bb387061(v = vs.120).aspx [ ^ ]
VB.Net代码为:< br $> b $ b
Dim custDB = _
< CustDB >
< / CustDB >
Dim customer = _
< 客户 >
< 名称 > Mr test < / Name >
< Address1 > 添加1 < / Address1 >
< 地址2 > 添加2 < / Address2 >
< 电话 > < /电话 >
< 传真 > < ; / Fax >
< Cell > < / Cell >
< 其他 > < /其他 >
< ; Attn > < / Attn >
< 电子邮件 > < /电子邮件 >
< SalesPerson > < / SalesPerson >
< /客户 >
custDB.Add(客户)
就这么简单。
Valery
I have an XAML doc that has several textboxes for customer name and contact data (i.e. address, phone, fax, contact name, email address). I have a sub that checks the bound xml document to see if the customer name already exists and if not it creates a new entry for all the text boxes. At least that's the idea. I know there has got to be a way to append all the XMLElements to the source in one fell swoop, but I can't seem to figure out how to streamline this event. I want to include all indenting and XML validation as well.
XML data is formated as such...
<?xml version="1.0" encoding="utf-8"?>
<CustDB xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Customer>
<Name></Name>
<Address1></Address1>
<Address2></Address2>
<Phone></Phone>
<Fax></Fax>
<Cell></Cell>
<Other></Other>
<Attn></Attn>
<Email></Email>
<SalesPerson></SalesPerson>
</Customer>
</CustDB>
hello,
Linq to XML.
http://msdn.microsoft.com/en-us/library/bb387061(v=vs.120).aspx[^]
The VB.Net code is:
Dim custDB = _ <CustDB> </CustDB> Dim customer = _ <Customer> <Name>Mr test</Name> <Address1>Add 1</Address1> <Address2>add 2</Address2> <Phone></Phone> <Fax></Fax> <Cell></Cell> <Other></Other> <Attn></Attn> <Email></Email> <SalesPerson></SalesPerson> </Customer> custDB.Add(customer)
it's that simple.
Valery.
这篇关于如何在WPF VB中向XML文件添加新的子集条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!