XmlDocument 방식을 사용하는 다른 노드 다음에 노드를 추가 할 수 없습니다. 내가 XMLdocument
의 방법을 시도했지만 그들은 내게 을 줄 것 같지 않습니다. 나는 아래이 새로운 노드 섹션을 추가 내 콘솔 응용 프로그램 코드의 코드를 실행노드를 기존 XML 문서에 삽입하는 동안 노드를 추가하려면 어떻게해야합니까?
<?xml version="1.0" encoding="UTF-8"?>
<FileZillaServer>
<Groups/>
<Users>
<User Name="dbrown">
<Option Name="Pass">2ac9cb7dc02b3c0083eb70898e549b63</Option>
<IpFilter>
<Disallowed/>
<Allowed/>
</IpFilter>
<Permissions>
<Permission Dir="C:\inetpub\wwwroot">
<Option Name="FileRead">1</Option>
</Permission>
</Permissions>
<SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10" ServerUlLimitBypass="0">
<Download/>
<Upload/>
</SpeedLimits>
</User>
</Users>
<User Name="3">
<Option Name="Pass"/>
<IPFilter>
<Disallowed/>
<Allowed/>
</IPFilter>
<Permissions>
<Permission Dir="C:\inetpub\wwwroot">
<Option Name="FileRead"/>
</Permission>
</Permissions>
<SpeedLimits DType="0" DLimit="10" ServerDLimitBypass="0" UType="0" ULimit="10" ServerULimitBypass="0">
<Download/>
<Upload/>
</SpeedLimits>
<PrivateFtpAccountId-3>55555</PrivateFtpAccountId-3>
<PrivatePassword-3>test5</PrivatePassword-3>
<PublicFtpAccountId-3>66666</PublicFtpAccountId-3>
<PublicPassword-3>test6</PublicPassword-3>
</User>
</FileZillaServer>
,하지만 난 그냥 처음 사용자 그룹 후에 추가 할 ---- : 같은
기존의 XML 파일이 보이는 > ....
<User Name="3">
<Option Name="Pass"/>
<IPFilter>
<Disallowed/>
<Allowed/>
</IPFilter>
<Permissions>
<Permission Dir="C:\inetpub\wwwroot">
<Option Name="FileRead"/>
</Permission>
</Permissions>
<SpeedLimits DType="0" DLimit="10" ServerDLimitBypass="0" UType="0" ULimit="10" ServerULimitBypass="0">
<Download/>
<Upload/>
</SpeedLimits>
<PrivateFtpAccountId-3>55555</PrivateFtpAccountId-3>
<PrivatePassword-3>test5</PrivatePassword-3>
<PublicFtpAccountId-3>66666</PublicFtpAccountId-3>
<PublicPassword-3>test6</PublicPassword-3>
</User>
작동하지 않는 것 같습니다.
내 콘솔 응용 프로그램 코드는 다음과 같습니다
Dim xmleUserNameRoot As XmlElement
Dim xmleOptionElement10 As XmlElement
Dim xmleOptionElement20 As XmlElement
Dim xmleOptionElement21 As XmlElement
Dim xmleOptionElement22 As XmlElement
Dim xmleOptionElement23 As XmlElement
Dim xmleIpFilterRoot As XmlElement
Dim xmlePermissionsGroup As XmlElement
Dim xmlePermissionRoot As XmlElement
Dim xmleSpeedLimits As XmlElement
Dim xmleElementPrivateFtpAcctId As XmlElement
Dim xmleElementPrivatePassword As XmlElement
Dim xmleElementPublicFtpAcctId As XmlElement
Dim xmleElementPublicPassword As XmlElement
Dim count As Integer
Dim strId As String
Dim strPrivateFtpAcctId As String
Dim strPrivatePassword As String
Dim strPublicFtpAcctId As String
Dim strPublicPassword As String
strPrivateFtpAcctId = "55555"
strPrivatePassword = "test5"
strPublicFtpAcctId = "66666"
strPublicPassword = "test6"
' Can be any Id.
strId = "3"
' Create a new XmlDocument class, and use the Load method to load the XML file.
Dim myXmlDocument As New XmlDocument()
' The XmlDocument class represents the XML document and has a Load method to load the document from a file, stream, or an XmlReader.
' So load in the XML file.
myXmlDocument.Load("MyFiLeZillaforadding.xml")
' For starting User Name.
xmleUserNameRoot = myXmlDocument.CreateElement("User")
' Create an attribute and set its value to that of the new id.
xmleUserNameRoot.SetAttribute("Name", strId)
myXmlDocument.DocumentElement.AppendChild(xmleUserNameRoot)
' Create a new element with an attribute and add it in to the User group.
xmleOptionElement1 = myXmlDocument.CreateElement("Option")
xmleOptionElement1.SetAttribute("Name", "Pass")
xmleUserNameRoot.AppendChild(xmleOptionElement1)
' Create the new "IPFilter" root.
xmleIpFilterRoot = myXmlDocument.CreateElement("IPFilter")
' Add elements to the "IPFilter" root.
xmleOptionElement20 = myXmlDocument.CreateElement("Disallowed")
xmleIpFilterRoot.AppendChild(xmleOptionElement20)
xmleOptionElement21 = myXmlDocument.CreateElement("Allowed")
xmleIpFilterRoot.AppendChild(xmleOptionElement21)
' Add the "IPFilter" root.
xmleUserNameRoot.AppendChild(xmleIpFilterRoot)
' Create the new "Permissions" group.
xmlePermissionsGroup = myXmlDocument.CreateElement("Permissions")
' Create the new "Permission" root.
xmlePermissionRoot = myXmlDocument.CreateElement("Permission")
xmlePermissionRoot.SetAttribute("Dir", "C:\inetpub\wwwroot")
' Add elements to the "Permission" root.
xmleOptionElement10 = myXmlDocument.CreateElement("Option")
xmleOptionElement10.SetAttribute("Name", "FileRead")
xmlePermissionRoot.AppendChild(xmleOptionElement10)
' Add the "Permission" root to the "Permissions" group.
xmlePermissionsGroup.AppendChild(xmlePermissionRoot)
' Add the "Permissions" group.
xmleUserNameRoot.AppendChild(xmlePermissionsGroup)
' Create the new "SpeedLimits" root.
xmleSpeedLimits = myXmlDocument.CreateElement("SpeedLimits")
xmleSpeedLimits.SetAttribute("ServerULimitBypass", "0")
xmleSpeedLimits.SetAttribute("ULimit", "10")
xmleSpeedLimits.SetAttribute("UType", "0")
xmleSpeedLimits.SetAttribute("ServerDLimitBypass", "0")
xmleSpeedLimits.SetAttribute("DLimit", "10")
xmleSpeedLimits.SetAttribute("DType", "0")
' Add elements to the "SpeedLimits" root.
xmleOptionElement22 = myXmlDocument.CreateElement("Download")
xmleSpeedLimits.AppendChild(xmleOptionElement22)
xmleOptionElement23 = myXmlDocument.CreateElement("Upload")
xmleSpeedLimits.AppendChild(xmleOptionElement23)
' Add the "SpeedLimits" root.
xmleUserNameRoot.AppendChild(xmleSpeedLimits)
' Add the remaining to User Name="#".
xmleElementPrivateFtpAcctId = myXmlDocument.CreateElement("PrivateFtpAccountId-" & strId)
xmleElementPrivateFtpAcctId.InnerText = strPrivateFtpAcctId
xmleUserNameRoot.AppendChild(xmleElementPrivateFtpAcctId)
xmleElementPrivatePassword = myXmlDocument.CreateElement("PrivatePassword-" & strId)
xmleElementPrivatePassword.InnerText = strPrivatePassword
xmleUserNameRoot.AppendChild(xmleElementPrivatePassword)
xmleElementPublicFtpAcctId = myXmlDocument.CreateElement("PublicFtpAccountId-" & strId)
xmleElementPublicFtpAcctId.InnerText = strPublicFtpAcctId
xmleUserNameRoot.AppendChild(xmleElementPublicFtpAcctId)
xmleElementPublicPassword = myXmlDocument.CreateElement("PublicPassword-" & strId)
xmleElementPublicPassword.InnerText = strPublicPassword
xmleUserNameRoot.AppendChild(xmleElementPublicPassword)
' Get the first User.
' ----> Can't see to get the first user. I tried a number of the XmlDocument methods with no sucess.
' Add the whole User Name="#" group after this first User.
' Save in place.
myXmlDocument.Save("MyFiLeZillaforadding.xml")
Console.WriteLine("The XML file was saved successfully.")
감사합니다 ...
당신이 문서에 추가하고자하는 새로운 데이터의 '사용자'노드를 만드는 것 같습니다
'첫 번째 사용자를 확보하십시오. '----> 첫 번째 사용자를 확보 할 수 없습니다. XmlDocument 메서드를 성공적으로 시도했습니다. '첫 번째 사용자 다음에 전체 User Name = "#"그룹을 추가하십시오. – user3020047
곧 Enter 키를 누르십시오. 하하. 어쨌든 .. 그 AppendChild 코드는 거기에 속하지 않습니다. User 노드를 찾으면 맨 아래에 속합니다. 내가 가지고있는 문제는 사용자 childnode를 찾는 대부분의 방법을 시도했지만 성공하지 못했다는 것입니다. 내가 뭘 잘못하고 있었는지 확실하지 않았다 ... 그리고 기본적으로 토론을 위해 그 메소드 호출 시도를 삭제했다. – user3020047
당신이하려는 일을 정확하게 이해한다면 사용자 자식 노드를 찾을 필요가 없습니다. 당신이 필요로하는 것은'Users' 부모 노드를 찾고 그 끝에 새로운 노드를 추가하는 것입니다.이 경우 새로운 노드가 첫 번째 기존 사용자 노드 옆에 추가됩니다. – Anthony