What’s the easiest way to achive the below.
Just to embedd the ‘project’ into a newly created ‘event’
Should I get the textual version of ‘project’, create a new child ‘event’ at the index before ‘project’, delete ‘project’ and insert the ‘old project’ there?
set xmlString to "<somexml version=\"1.1\">
<import-options/>
<project name=\"Project\">
<sequence duration=\"48\">
</sequence>
</project>
</somexml>"
set theElement to current application's NSXMLElement's alloc()'s initWithXMLString:xmlString |error|:(missing value)
set theProj to (theElement's elementsForName:"project")'s firstObject()
theProj's detach()
set newNode to current application's NSXMLNode's elementWithName:"event" children:{theProj} attributes:(missing value)
theElement's addChild:newNode
I gave a bad example, so the final code should look like:
set xmlString to "<somexml version=\"1.1\">
<import-options/>
<project name=\"Project\">
<sequence duration=\"48\">
</sequence>
</project>
<additional/>
<additional/>
</somexml>"
set theElement to current application's NSXMLElement's alloc()'s initWithXMLString:xmlString |error|:(missing value)
set theProj to (theElement's elementsForName:"project")'s firstObject()
set theProjIdx to (theProj's |index|) as integer
theProj's detach()
set newNode to current application's NSXMLNode's elementWithName:"event" children:{theProj} attributes:(missing value)
(theElement's insertChild:newNode atIndex:theProjIdx)