我很难将新的XmlElement
添加到XML文件中的特定节点上。我想写一个Trf
的新实例,它在Transfers中。代码下方是添加到我的默认文件中的内容。
为了显示XML文件中的所有数据,某些行在同一行显示3 <something>
,但在文件导出中其格式正确。
我已经开始考虑使用NamespaceManager
,但是在实现它方面没有任何运气。 WTF
和MATE
似乎出现在TransfersRequest根目录下。试图弄清楚如何将其放在/etf:TransfersRequest/etf:Data/etf:Send/etf:Transfers
下。
Imports xmlns:etf="http://SomeNamespace" '(<> instead of "")
Imports System.Xml.XmlDocument
Imports System.Xml
Dim sender, name As String
sender = "WTF"
name = "MATE"
Dim myDoc As Xml.XmlDocument = New Xml.XmlDocument
myDoc.SelectSingleNode("Send")
myDoc.Load(file.xml)
Dim myTrf As XmlElement = myDoc.CreateElement("etf:Trf", "http://SomeNamespace")
Dim mySender As XmlElement = myDoc.CreateElement("etf:Sender", "http://SomeNamespace")
Dim myName As XmlElement = myDoc.CreateElement("etf:Name", "http://SomeNamespace")
myName.InnerText = sender
Dim myString As XmlElement = myDoc.CreateElement("etf:Status", "http://SomeNamespace")
myString.InnerText = name
myTrf.AppendChild(mySender)
myTrf.AppendChild(myName)
mySender.AppendChild(myString)
myDoc.DocumentElement.FirstChild.AppendChild(myTrf)
myDoc.Save(file.xml)
这是我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<etf:TransfersRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlsn="http://www.rbc.com/xmlns/ips/etf/2015-06-10-PROPOSAL/v1" xmlns:etf="http://SomeNamespace"> <etf:Header>
<etf:BatchReferenceNumber>????></etf:BatchReferenceNumber>
<etf:CreationDateTime>2018-12-05T16:21:40Z</etf:CreationDateTime>
<etf:Client>
<etf:Id>123456789</etf:Id>
<etf:AccountHolderName>Depot Name(get from config)</etf:AccountHolderName>
<etf:AccountNumber>
</etf:AccountNumber>
</etf:Client>
<etf:Type>SendTransfersRequest</etf:Type>
<etf:Trf>
<etf:Sender>
<etf:Status>MATE</etf:Status>
</etf:Sender>
<etf:Name>WTF</etf:Name>
</etf:Trf> </etf:Header> <etf:Data>
<etf:Send>
<etf:Sender>
<etf:Name>AccountHolderName</etf:Name>
</etf:Sender>
<etf:ProcessingOptions>
<etf:Priority>0</etf:Priority>
<etf:ReminderMaxCount>3</etf:ReminderMaxCount>
</etf:ProcessingOptions>
<etf:Currency>CAD</etf:Currency>
<etf:Transfers>
<etf:Trf>
<etf:Sender>
<etf:Name>Depot Name(get from config)</etf:Name>
</etf:Sender>
<etf:Recipient>
<etf:Name>
</etf:Name>
<etf:Eamil>
</etf:Eamil>
<etf:Language>en</etf:Language>
</etf:Recipient>
<etf:Authentication>
<etf:Question>Your client number?</etf:Question>
<etf:Answer>
</etf:Answer>
</etf:Authentication>
<etf:Amount>
</etf:Amount>
<etf:Memo>
</etf:Memo>
<etf:ReferenceNumber>
</etf:ReferenceNumber>
</etf:Trf>
</etf:Transfers>
</etf:Send> </etf:Data> <etf:Trailer>
<etf:TotalTransfers>
</etf:TotalTransfers>
<etf:TotalAmount>
</etf:TotalAmount>
</etf:Trailer>
</etf:TransfersRequest>