With a little side of applesauce...

Tuesday, August 26, 2008

Coldfusion / OpenDocument Format - add an xmlchild to the body of an odt zip

This post uses the library from my last post and adds a simple text:p entry into our document, and includes some XmlAttributes for future reference:

    <cfobject name="cfcOpenDocumentFormat" component="wf.class.OpenDocumentFormat">
<cfset variables.xmlContent = cfcOpenDocumentFormat.zipReadFile( "content.xml", path )>

<cfset variables.content = xmlParse(variables.xmlContent)>
<!--- now, let's insert our information into the document (username, time/date, state, comments, title) --->

<!--- create our comment node and add text --->
<cfset xmlComment = XmlElemNew( variables.content, "urn:oasis:names:tc:opendocument:xmlns:text:1.0", "text:p") />
<cfset xmlComment.xmlText = "#form.comment#">
<cfset xmlComment.XmlAttributes.Comment = "Yes">
<cfset xmlComment.XmlAttributes.User = "#Session.username#">
<cfset xmlComment.XmlAttributes.UserFullName = "#Session.UserFullName#">
<cfset xmlComment.XmlAttributes.DateTime = cfcOpenDocumentFormat.getDocumentCreationDateTime()>
<cfset xmlComment.XmlAttributes.State = "#Session.state#">
<cfset xmlComment.XmlAttributes.User = "#Session.UserFullName#">
<cfset xmlComment.XmlAttributes.Status = "#form.accept#">
<cfset ArrayAppend( variables.content.xmlRoot.XmlChildren[2].XmlChildren[1].XmlChildren, xmlComment ) />

<!--- update the zip file --->
<cfset variables.xmlContent = cfcOpenDocumentFormat.zipUpdateFile( "content.xml", path, variables.content )>

No comments: