Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML add nodes to closed (childless) node
#1
I want to add to "EPP/Bookmarks"

Code:
Copy      Help
<Bookmark name="TESTNAME" Description="" Type="1" ShowOnBookmarksToolbar="yes" Location="C:\test"/>

To a node that is "closed"
<Bookmarks />

The result should be:
Code:
Copy      Help
...
<Bookmarks>
   <Bookmark name="TESTNAME" Description="" Type="1" ShowOnBookmarksToolbar="yes" Location="C:\test"/>
</Bookmarks>
...


Look at the below code and green comments (below green comment 'Actual result' and 'Desired result' , regarding <Bookmarks />)



Macro Macro9
Code:
Copy      Help
str addnode="Bookmark" ;; This node get's added to 'EPP/Bookmarks'

;; Note here that 'Bookmark' is closed ==>  <Bookmarks />
str xml_source=
;<?xml version="1.0" ?>
;<EPP>
,;<Bookmarks />
,;<ApplicationToolbar>
,,;<ApplicationButton name="test" Command="c:\test.txt" ShowNameOnToolbar="yes" />
,;</ApplicationToolbar>
,;<Toolbars>
,,;<Toolbar name="0" id="0" Style="641" Length="281" />
,,;<Toolbar name="1" id="3" Style="640" Length="629" />
,;</Toolbars>
;</EPP>

IXml x._create
IXmlNode e
x.FromString(xml_source)
int i

e=x.Path("EPP/Bookmarks")
e.Add(addnode)
e.SetAttribute("name" "TESTNAME")
e.SetAttribute("Description" "")
e.SetAttribute("Type" "1")
e.SetAttribute("ShowOnBookmarksToolbar" "yes")
e.SetAttribute("Location" "c:\test")

str s
x.ToString(s)
out s



;Actual result:
;----------------------------------
;<?xml version="1.0" ?>
;<EPP>
,;<Bookmarks name="TESTNAME" Description="" Type="1" ShowOnBookmarksToolbar="yes" Location="c:\test">
,,;<Bookmark />
,;</Bookmarks>
,;<ApplicationToolbar>
,,;<ApplicationButton name="test" Command="c:\test.txt" ShowNameOnToolbar="yes" />
,;</ApplicationToolbar>
,;<Toolbars>
,,;<Toolbar name="0" id="0" Style="641" Length="281" />
,,;<Toolbar name="1" id="3" Style="640" Length="629" />
,;</Toolbars>
;</EPP>



;Desired result:
;----------------------------------
;<?xml version="1.0" ?>
;<EPP>
,;<Bookmarks>
,,;<Bookmark name="TESTNAME" Description="" Type="1" ShowOnBookmarksToolbar="yes" Location="C:\test"/>
,;</Bookmarks>
,;<ApplicationToolbar>
,,;<ApplicationButton name="test" Command="c:\test.txt" ShowNameOnToolbar="yes" />
,;</ApplicationToolbar>
,;<Toolbars>
,,;<Toolbar name="0" id="0" Style="641" Length="281" />
,,;<Toolbar name="1" id="3" Style="640" Length="629" />
,;</Toolbars>
;</EPP>
#2
e.Add(addnode) ;;error
e=e.Add(addnode) ;;correct
#3
YES!!!!!!!
THANK YOU!!!
It works!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)