Working with NSXML

Im working on a project that gathers not only tableview data but also text field / popup data and formats it into a XML output. My problem is that I don’t know how to back out of the current Node that I am in.

Im looking to have my XML structured as













Shane has been helping me a ton with this project, I figured with the time change and the fact im in a pinch I would come to the forums :slight_smile:
The Problem is that I am not getting the Node to show up and I really don’t understand how to go up levels in the XML.

set jobsNode to (current application's NSXMLNode's elementWithName_("CMSARESULT"))
			set theDoc to current application's NSXMLNode's documentWithRootElement_(jobsNode)
			tell theDoc
				setVersion_("1.0")
				setCharacterEncoding_("UTF-8")
			end tell

set jobNode to (current application’s NSXMLNode’s elementWithName_(“CreateJobParameters”))
set RealNameNode to (current application’s NSXMLNode’s elementWithName_stringValue_(“OrderID”, (orderID’s stringValue() as string)))
jobNode’s addChild_(RealNameNode)
set SubOrderNode to (current application’s NSXMLNode’s elementWithName_stringValue_(“SubOrderID”, (subOrderID’s stringValue() as string)))
jobNode’s addChild_(SubOrderNode)

set tableData to (theArrayController’s arrangedObjects()) as list
repeat with i from 1 to count of tableData
set jobNode to (current application’s NSXMLNode’s elementWithName_(“JOB”))
set fileNameNode to (current application’s NSXMLNode’s elementWithName_stringValue_(“FileName”, thePath of item i of tableData))
jobNode’s addChild_(fileNameNode)
set quantityNode to (current application’s NSXMLNode’s elementWithName_stringValue_(“Quantity”, (theQuantity of item i of tableData) as text))
jobNode’s addChild_(quantityNode)
set materialNode to (current application’s NSXMLNode’s elementWithName_stringValue_(“Material”, (theMaterial of item i of tableData) as text))
jobNode’s addChild_(materialNode)
try
set oneDate to theDate of item i of tableData
set oneDate to dateFormatter’s stringFromDate_(oneDate)
set dateNode to (current application’s NSXMLNode’s elementWithName_stringValue_(“DueDate”, oneDate))
jobNode’s addChild_(dateNode)
on error
display dialog “No date was specified!”
end try
jobsNode’s addChild_(jobNode)
end repeat

It’s not really a question of “backing out”. When you create a new XMLElement, it doesn’t belong anywhere until you put it somewhere, usually using addChild_ (you can also use setChildren_, insertChild_atIndex_, etc). So if it helps, you can make all the nodes first, then add them to the parent nodes they belong to.