I have been emailing Bryan and James off-list, and Bryan found the issue. I
am posting the solution here for anyone else that may encounter it in the
future.

It has nothing to do with XML at all... leading spaces are being stripped in
the parser, before XML-encoding begins. And it isn't really a problem... I
was unaware that the HL7 spec mandates stripping leading spaces. The parser
is just doing what it's supposed to do. Unfortunately, it's not what I need
it to do.

The solution, as Bryan wrote to me:
> The HL7 spec has a rule against leading whitespaces, and HAPI enforces
> this by stripping them, but this is 
> configurable. Here are the relevant lines in
> ca.uhn;hl7v2.validation.impl.DefaultValidation:
> 
> Rule trim = new TrimLeadingWhitespace();
> getPrimitiveRuleBindings().add(new RuleBinding("*", "FT", trim)); 
> getPrimitiveRuleBindings().add(new RuleBinding("*", "ST", trim));
> getPrimitiveRuleBindings().
> add(new RuleBinding("*", "TX", trim));
> 
> You could try changing these rules by providing your own ValidationContext
> to the Parser.

So what I did was subclass DefaultValidation and added the following:
        super();
        Iterator iter = getPrimitiveRuleBindings().listIterator();
        for (int i = 0, n = getPrimitiveRuleBindings().size(); i < n; i++)
        {
            Object o = iter.next();
            if (o instanceof RuleBinding)
            {
                RuleBinding binding = (RuleBinding) o;
                if (binding.getActive()
                        && binding.appliesToVersion("*")
                        && binding.appliesToScope("TX"))
                {
                    iter.remove();
                    if (log.isDebugEnabled())
                        log.debug("Rule removed: " +
                                  binding.getVersion() + " " +
                                  binding.getScope() + " " +
                                  binding.getRule().getClass().getName() + "
" +
                                  binding.getRule().getDescription());
                }
            }
        }

This removes the leading-whitespace stripping for all TX fields while
leaving all the other default validations intact.

Greg Groves
Florida Hospital
-- 
View this message in context: 
http://www.nabble.com/Preserving-spaces-in-XML-text-nodes-tf3415885.html#a9718209
Sent from the hl7api-devel mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to