A POCO stands for Plain Old CLR object, it simply means a class with only public properties and no functionality, for example in Jiwa the Sales Order object is not a POCO as it contains functionality but JiwaFinancials.Jiwa.JiwaSales.SalesOrder.XML.SalesOrder is, as it is the structure onto which the sales order can be mapped and then serialized to XML.
Similarly a DTO, Data Transfer Object is used for a similar purpose in the api and does not contain functionality.
What Mike is saying is the XML does not map correctly for things like lists, so its not actually legitimate XML in the strictest sense.
The Code Mike was referring to is below where he uses the XML document to move the nodes and then removes the unwanted nodes, if you follow the same logic steps for dangerous goods you should get the desired result in adding to this function.
- Code: Select all
Public Function Serialise() As System.Xml.XmlDocument
' About the SmartFreight XML Format
' =================================
' Unfortunately the smartfreight XML format does not map nicely to a POCO's with lists. An example is the freightlines.
'
'Example showing multiple freight lines:
'<connotes>
' <connote>
' <freightlinedetails>
' <ref>MY REF 1111</ref>
' <desc>CARTON</desc>
' <amt>6</amt>
' <wgt>52.45</wgt>
' </freightlinedetails>
' <freightlinedetails>
' <desc>PALLET</desc>
' <amt>1</amt>
' <wgt>112</wgt>
' </freightlinedetails>
' </connote>
'</connotes>
'Example showing multiple freight lines if it were mappable directly to a POCO:
'<connotes>
' <connote>
' <freightlinedetails>
' <freightlinedetail>
' <ref>MY REF 1111</ref>
' <desc>CARTON</desc>
' <amt>6</amt>
' <wgt>52.45</wgt>
' </freightlinedetail>
' <freightlinedetail>
' <desc>PALLET</desc>
' <amt>1</amt>
' <wgt>112</wgt>
' <freightlinedetail>
' </freightlinedetails>
' </connote>
'</connotes>
'
' So, we can't simply serialise the whole connote - we need to serialise then remove the freightlines node,
' then add the each freightline manually. If we didn't have to do this, serialise would be as simple as:
'Dim stringWriter As New System.IO.StringWriter
'Dim xmlSerializer As New System.Xml.Serialization.XmlSerializer(GetType(XML.connote))
'Dim xmlNamespaces As New System.Xml.Serialization.XmlSerializerNamespaces()
'xmlNamespaces.Add("", "")
'xmlSerializer.Serialize(stringWriter, Me, xmlNamespaces)
'Return stringWriter.ToString
'stringWriter.Close()
'stringWriter.Dispose()
If applyleastcost Then
applyleastcostSpecified = True
End If
Dim xmlDocument As New System.Xml.XmlDocument()
Dim xPathNavigator As System.Xml.XPath.XPathNavigator = xmlDocument.CreateNavigator()
Using xmlWriter As System.Xml.XmlWriter = xPathNavigator.AppendChild()
Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(XML.connote), "")
ser.Serialize(xmlWriter, Me)
End Using
Dim conNoteNode As System.Xml.XmlNode = xmlDocument.SelectSingleNode("/connote")
' Now find the parent freightlinedetails node
Dim freightlinedetailscontainerNode As System.Xml.XmlNode = xmlDocument.SelectSingleNode("/connote/freightlinedetails")
If freightlinedetailscontainerNode IsNot Nothing Then
'Move all the child nodes to their grandparent (the connote)
While freightlinedetailscontainerNode.HasChildNodes
conNoteNode.InsertBefore(freightlinedetailscontainerNode.ChildNodes(0), freightlinedetailscontainerNode)
End While
' Remove the container node
conNoteNode.RemoveChild(freightlinedetailscontainerNode)
End If
' Now find the additional references node
Dim additionalReferencesContainerNode As System.Xml.XmlNode = xmlDocument.SelectSingleNode("/connote/additionalreferences")
If additionalReferencesContainerNode IsNot Nothing Then
' Remove the container node
conNoteNode.RemoveChild(additionalReferencesContainerNode)
' Add a new additionalreferences node
Dim additionalreferencesElement As System.Xml.XmlElement = xmlDocument.CreateElement("additionalreferences")
conNoteNode.AppendChild(additionalreferencesElement)
For Each additionalreference As additionalreference In additionalreferences
Dim referenceNoElement As System.Xml.XmlElement = xmlDocument.CreateElement("referenceno")
referenceNoElement.InnerText = additionalreference.referenceno
additionalreferencesElement.AppendChild(referenceNoElement)
Next
End If
Return xmlDocument
End Function