Over the last week I have been attempting to complete the project so that I can ensure I document the last few steps correctly. In the last post I created the Data Collection routing for generating the XML that needs to be pushed into the Custom Part. Since then I managed to create a automaton for pushing the XML into the custom part, however, when testing it in a test chassis I found that Word was struggling to understand attributes. The XML I created manually was fine but the XML generated through the script did not work. Having determined this but not determined why I have decided to take a step back and change the way that Data Collection creates the XML so that Word will work.
What do I mean: “Word does not work”? Well when I manually created the CustomPart and bound it to the Form Fields you could see the results on the page (binding form fields) as shown in the image below. Once I had automated the creation of the XML and the pushing of that XML into Word the content of the custom part was not showing in the document (the form was blank).
If I then went into Design mode to view the Form Field details and then switched back out of Design Mode I would get an error. It took me quite some time to realise that this error was simply saying that the Form Fields are empty. This seems a bad error (one that Microsoft needs to change).
Furthermore as the PASW name for Data Collection has been dropped by IBM, I decided to change my namespace from PASW to CaO2. CaO2 is an old term from a previous life, it has nothing to do with SPSS or IBM but I like using it (for example I use it as a domain name for my e-Mail: kgray@cao2.net)
To explain the change, let’s examine the name node of the xml. In the previous post the following XML would have been generated by Data Collection:
Word did not seem to like the namespace qualified attributes. Dropping the namespace for each attribute did work. So I could change the XML to:
However I am not happy doing this I like the namespace to be qualified properly. Consequently I have decided to only use textnodes and not use attributes. This will get me through this exercise but is not a perfect solution. As a consequence I will have to return to this in a later blog to ensure I can use attributes in the long run. The new XML will, consequently look like this:
This format is much more verbose but it does work when used in Word. In order to have this format of output the routing in Data Collection needs to change. The creation of an attribute was, previously, executed through the following code (which creates the name node and then adds a title attribute):
The new code will still create the name node but then will create another node for title. The title node is always created whether or not there is a title, however the textnode within the new node is only created if there is response on the form, otherwise the title node will be null.
Routing(Web)
Dim xmlPart, xmlNode, xmlRoot, xmlPersonal, xmlIncident, xmlParent, xmlText
Const Node_Element = 1
IOM.LayoutTemplate = "railcomplaint"
IOM.MustAnswer = false
Personal.Ask()
Incident.Ask()
set xmlPart = CreateObject("Microsoft.XMLDOM")
set xmlRoot = xmlPart.createNode(Node_Element, "cao2:root", "http://www.kevinagray.co.uk/railcomplaint")
xmlPart.appendChild(xmlRoot)
set xmlPersonal = xmlPart.CreateNode(Node_Element, "cao2:personal", "http://www.kevinagray.co.uk/railcomplaint")
xmlRoot.appendChild(xmlPersonal)
set xmlIncident = xmlPart.CreateNode(Node_Element, "cao2:incident", "http://www.kevinagray.co.uk/railcomplaint")
xmlRoot.appendChild(xmlIncident)
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:when", "http://www.kevinagray.co.uk/railcomplaint")
xmlIncident.appendChild(xmlParent)
if IncidentDate.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentDate.Response.Value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:destination", "http://www.kevinagray.co.uk/railcomplaint")
xmlIncident.appendChild(xmlParent)
if IncidentDestination.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentDestination.Response.Value)
xmlParent.appendChild(xmlText)
end if
set xmlNode = xmlPart.CreateNode(Node_Element, "cao2:name", "http://www.kevinagray.co.uk/railcomplaint")
xmlPersonal.appendChild(xmlNode)
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:title", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if Title.Response.Value <> null then
set xmlText = xmlPart.createTextNode(format(Title.Response,"b"))
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:fname", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if fname.Response.Value <> null then
set xmlText = xmlPart.createTextNode(fname.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:lname", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if lname.Response.Value <> null then
set xmlText = xmlPart.createTextNode(lname.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlNode = xmlPart.CreateNode(Node_Element, "cao2:address", "http://www.kevinagray.co.uk/railcomplaint")
xmlPersonal.appendChild(xmlNode)
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:line1", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if address1.Response.Value <> null then
set xmlText = xmlPart.createTextNode(address1.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:line2", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if address2.Response.Value <> null then
set xmlText = xmlPart.createTextNode(address2.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:town", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if Town.Response.Value <> null then
set xmlText = xmlPart.createTextNode(town.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:postcode", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if PostCode.Response.Value <> null then
set xmlText = xmlPart.createTextNode(postcode.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlNode = xmlPart.CreateNode(Node_Element, "cao2:contact", "http://www.kevinagray.co.uk/railcomplaint")
xmlPersonal.appendChild(xmlNode)
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:work", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if Phone.Response.Value <> null then
set xmlText = xmlPart.createTextNode(phone.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:home", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if Phone2.Response.Value <> null then
set xmlText = xmlPart.createTextNode(Phone2.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:mobile", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if mobile.Response.Value <> null then
set xmlText = xmlPart.createTextNode(mobile.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:email", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if email.Response.Value <> null then
set xmlText = xmlPart.createTextNode(email.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlNode = xmlPart.CreateNode(Node_Element, "cao2:departure", "http://www.kevinagray.co.uk/railcomplaint")
xmlIncident.appendChild(xmlNode)
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:from", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if IncidentDepart.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentDepart.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:expected", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if IncidentExpected.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentExpected.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:actual", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if IncidentActual.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentActual.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlNode = xmlPart.CreateNode(Node_Element, "cao2:impact", "http://www.kevinagray.co.uk/railcomplaint")
xmlIncident.appendChild(xmlNode)
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:severity", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if IncidentSeverity.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentSeverity.Response.
value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:outcome", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if ExpectedOutcome.Response.Value <> null then
set xmlText = xmlPart.createTextNode(ExpectedOutcome.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlParent = xmlPart.CreateNode(Node_Element, "cao2:cost", "http://www.kevinagray.co.uk/railcomplaint")
xmlNode.appendChild(xmlParent)
if CostIncurred.Response.Value <> null then
set xmlText = xmlPart.createTextNode(CostIncurred.Response.value)
xmlParent.appendChild(xmlText)
end if
set xmlNode = xmlPart.CreateNode(Node_Element, "cao2:description", "http://www.kevinagray.co.uk/railcomplaint")
xmlIncident.appendChild(xmlNode)
if IncidentDescription.Response.Value <> null then
set xmlText = xmlPart.createTextNode(IncidentDescription.Response.Value)
xmlParent.appendChild(xmlText)
end if
debug.Log(xmlPart.xml)
End Routing