Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML add second subnode through "add"
#1
I have the below XML in the xml string "xml_str"
I have a problem generating a desired result which is explained below in the green comment.


Macro Macro6
Code:
Copy      Help
str xml_str=
;<?xml version="1.0" encoding="UTF-8" ?>
;<FreeFileSync XmlFormat="6" XmlType="BATCH">
,;<MainConfig>
,,;<Comparison>
,,,;<Variant>TimeAndSize</Variant>
,,,;<Symlinks>Exclude</Symlinks>
,,,;<IgnoreTimeShift />
,,;</Comparison>
,,;<SyncConfig>
,,,;<Variant>Mirror</Variant>
,,,;<CustomDirections>
,,,,;<LeftOnly>right</LeftOnly>
,,,,;<Conflict>none</Conflict>
,,,;</CustomDirections>
,,,;<DetectMovedFiles>false</DetectMovedFiles>
,,,;<DeletionPolicy>Permanent</DeletionPolicy>
,,,;<VersioningFolder Style="Replace" />
,,;</SyncConfig>
,,;<GlobalFilter>
,,,;<Include>
,,,,;<Item>*</Item>
,,,;</Include>
,,,;<Exclude>
,,,,;<Item>\System Volume Information\</Item>
,,,;</Exclude>
,,,;<TimeSpan Type="None">0</TimeSpan>
,,,;<SizeMin Unit="None">0</SizeMin>
,,,;<SizeMax Unit="None">0</SizeMax>
,,;</GlobalFilter>
,,;<FolderPairs>
,,,;<Pair>
,,,,;<Left>d:\test</Left>
,,,,;<Right>z:\test</Right>
,,,;</Pair>
,,;</FolderPairs>
,,;<OnCompletion />
,;</MainConfig>
,;<BatchConfig>
,,;<HandleError>Ignore</HandleError>
,,;<RunMinimized>false</RunMinimized>
,,;<LogfileFolder Limit="0" />
,;</BatchConfig>
;</FreeFileSync>

ARRAY(IXmlNode) ax
IXml x._create
IXmlNode e
int i

x.FromString(xml_str)
e=x.Path("/FreeFileSync/MainConfig/FolderPairs" ax 1)        
e.Add("Pair" "").Add("Left" "L")
e.Add("Pair" "").Add("Right" "R") ;; <==== second subnode, but does NOT generate desired result

;;......................
;Actual result:
;<Pair>
,;<Left>L</Left>
;</Pair>
;<Pair>
,;<Right>R</Right>
;</Pair>
;;......................
;Desired result: <<==================================
;<Pair>
,;<Left>d:\test</Left>
,;<Right>z:\test</Right>
;</Pair>
;<Pair>
,;<Left>L</Left>
,;<Right>R</Right>
;</Pair>
;;......................

x.ToString(_s)
out _s

Above in the green commented code you see what I want to achieve.
#2
IXmlNode e2=e.Add("Pair" "")
e2.Add("Left" "L")
e2.Add("Right" "R")

or

e.Add("Pair" "").Add("Left" "L").Parent.Add("Right" "R")
#3
Thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)