Here’s the situation: I have a client who’s issued me an XML schema, and my software converts their records from tab-delimited to XML.
One of those fields, “file-sequence,” is typed as an integer in the schema. However, the client’s client (the integration target) wants that integer zero-padded and 4 digits long (EG, <file-sequence>0001</file-sequence>) in the actual output XML.
I’m outputting using serialization, which is nice and automatic and painless. However, because the field is typed as an integer in the XSD, the file-sequence field comes out as <file-sequence>1</file-sequence>. Which makes sense. 🙂
So far I’ve narrowed potential answers down to three options:
-
Edit the schema and change the type to string. Zero-pad the sequence number upon updating the field. Downside: I have to remember to do this anytime the integration target changes the schema (as they have about a half-dozen times already).
-
Forego using XML serialization, manually generating the XML in code. Downside: A lot of work, possibly error-prone, a serious code-smell (to me).
-
Serialize to an in-memory stream, get the raw XML out of that, pad the integer there. Downsides: Feels really dirty, still a lot of work.
Are there any other options? If not, which option here is the right way to do this? (I’m thinking option 1 is probably cleanest.)
Honestly, option 1 is the only real option. If the target cares about the number of characters in the string, then the field is not an integer; it’s a string that’s restricted only to numeric digits.