如何在VB.NET WPF中添加XML属性 [英] How to add XML Attributes in VB.NET WPF
本文介绍了如何在VB.NET WPF中添加XML属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为XML文档编写一个新的写入子,但我需要知道如何添加和属性到某个Xelement
I am writing a new sub to writer to an XML document, but I need to know how to add and attribute to a certain Xelement
Dim xdoc As XDocument = Nothing
Dim xEle As XElement = Nothing
Dim xNode As XElement = Nothing
'create new document
xdoc = New XDocument
'add root
xEle = New XElement("CurrentJobs")
xdoc.Add(xEle)
'add jobs
For Each job As JobBoard In Jobs
xNode = New XElement("Job")
xNode.Add(New XElement("CustomerName", job.JobName))
xNode.Add(New XElement("PurchaseOrder", job.JobName))
xEle.Add(xNode)
Next
xdoc.Save(jFileName)
我正在加入e属性
I am adding the attribute
status="a-current"
到'Job'标签。所以输出看起来像......
to the 'Job' tag. so the output looks like...
<?xml version="1.0" encoding="utf-8"?>
<CurrentJobs>
<Job status="a-current">
<CustomerName>St Michael</CustomerName>
<PurchaseOrder></PurchaseOrder>
</Job
推荐答案
具体方法如下: http ://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.setattributevalue%28v=vs.110%29.aspx [ ^ ]。
但是,你确定你真的需要处理XML级别?许多人这样做可以在没有直接使用XML的情况下使用序列化来实现。
-SA
This is how: http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.setattributevalue%28v=vs.110%29.aspx[^].
However, are you sure that you really need to deal with XML level? Many people doing that could do it without direct use of XML, using serialization.
—SA
你的意思是:
You mean like:
xNode.Add(New XAttribute("status", "a-current"))
这篇关于如何在VB.NET WPF中添加XML属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文