A flat file schema can be configured to generate empty elements for empty content
– using the “Generate Empty Nodes” option.
It seems that at runtime, the flat file dissasembler can generate “<foo></foo>”
for these empty nodes in cases where “Validate Instance…”
in the IDE would have generated “<foo/>”.
Where this can cause pain is if you receive a message like: “<foo><bar></bar></foo>”
into your orchestration, and then do a series of assignments like:
xmlDocVariable = myMessage; // xmlDocVariable2 initialized because xmlDocVariable is needed for other things... xmlDocVariable2.LoadXml(xmlDocVariable.OuterXml); myMessage2 = xmlDocVariable2;
At this point, myMessage2 is going to be the serialized representation of xmlDocVariable2.
By default, you will now get:
<foo> ..<bar> ..</bar> </foo>
Notice you now have carriage returns, line feeds, and spaces (shown here as periods)
involved. Depending on how you now go after /foo/bar, this can be bad (i.e.
you won’t get empty content when you might expect it.) You can avoid this
behavior by doing:
xmlDocVariable2.LoadXml(xmlDocVariable.OuterXml); xmlDocVariable2.PreserveWhitespace = true; myMessage2 = xmlDocVariable2;
Thanks to Tomas and Carlos for
setting me straight on PreserveWhitespace – I was trying to set it before the
call to LoadXml, and this doesn’t work. Never a dull day in BizTalk land…
The documentation
for PreserveWhitespace is a little strange. This functionality would seem
to be better represented as parameters to Load/Save, rather than as a property…
“If PreserveWhitespace is true before Load or LoadXml is called, white
space nodes are preserved; otherwise, if this property is false, significant white
space is preserved, white space is not. If PreserveWhitespace is true before
Save is called, white space in the document is preserved in the output; otherwise,
if this property is false, XmlDocument auto-indents the output.”