• 共享
  • ?
  • 个人档案 ▼
  • 社区 ▼
  • 应用程序 ▼

博客

  • 我的博客
  • 公共博客
  • 我的更新

此社区可以包含贵组织以外的成员。 HermannSW

  • 登录以进行参与

▼ 标签

▼ 归档

  • 2018年3月
  • 2017年11月
  • 2017年5月
  • 2017年4月
  • 2017年3月
  • 2017年2月
  • 2017年1月
  • 2016年12月
  • 2016年10月
  • 2016年5月
  • 2016年4月
  • 2016年1月
  • 2015年12月
  • 2015年11月
  • 2015年10月
  • 2015年9月
  • 2015年8月
  • 2015年7月
  • 2015年6月
  • 2015年5月
  • 2015年3月
  • 2015年2月
  • 2015年1月
  • 2014年12月
  • 2014年11月
  • 2014年10月
  • 2014年9月
  • 2014年8月
  • 2014年7月
  • 2014年6月
  • 2014年5月
  • 2014年4月
  • 2014年3月
  • 2014年2月
  • 2014年1月
  • 2013年12月
  • 2013年11月
  • 2013年10月
  • 2013年9月
  • 2013年8月
  • 2013年7月
  • 2013年6月
  • 2013年5月
  • 2013年4月
  • 2013年3月
  • 2013年2月
  • 2013年1月
  • 2012年12月
  • 2012年11月
  • 2012年10月
  • 2012年9月
  • 2012年8月
  • 2012年7月
  • 2012年6月
  • 2012年5月
  • 2012年4月
  • 2012年3月
  • 2012年2月
  • 2012年1月
  • 2011年12月
  • 2011年11月
  • 2011年10月
  • 2011年9月
  • 2011年8月
  • 2011年7月
  • 2011年6月
  • 2011年5月
  • 2011年4月
  • 2011年3月
  • 2011年2月
  • 2011年1月

▼ 博客作者

HermannSW

查看所有条目
单击此按钮可以刷新整个页面。用户可以转至“条目列表”区域查看新内容。) 条目列表

Converting legacy 8bit data, again

HermannSW 2700006U54 | ‎ | 4,031 次访问

Back in 2010 I gave WSTE webcast WebSphere DataPower SOA Appliances and XSLT (Part 2 of 2) - Tips and Tricks.

On slide 7 of that webcast I did provide solutions on how to convert Non-XML input from legacy systems to XML by

  • wrapping with a <wrapper> element
  • replacing all bytes in the ASCII control character range (0x00-0x1F) by space character (0x20)
  • prepending xml declaration with ISO-8859-1 encoding for easily dealing with bytes (0x80-0xFF)


Last July I did blog posting on Doing recursion right on how I had to improve my smtp blog posting because I did not follow my own "Doing recursion right" slide 5 from above webcast. Better testing would have uncovered the problem in the first place.


Coming back to this blog posting, in last Saturday's developerWorks DataPower forum posting Non-xml to XML convertion issue  Vishnu identified an issue.
Again, better testing above metioned slide 7 stylesheets would have resulted in correct stylesheets in the first place.

The whole purpose of stylesheet conversion-wrapper2.xsl was to convert (arbitrary) Non-XML to XML.

While the output looks like XML it is not always, and Vishnu identified the root cause:

ampersand as well as less than characters were not escaped, and whenever they occur on input, invalid XML is the result.

The simple fix is just have the recursive stylesheet replace the 0x26 byte (ampersand) and the 0x3C byte (less than) by their escaped representations:

$ diff conversion-wrapper2.xsl conversion-wrapper2a.xsl
15a16,17
>       <xsl:when test="$char='26'">26616D703B</xsl:when>
>       <xsl:when test="$char='3c'">266C743B</xsl:when>
$


You can find old and new version of the stylesheet as well as the included hexBinary.ffd attached to this forum posting.

Files  gen.xsl,  test.table  and  identity.xsl  are attached there in addition.

The test that should fave been made back in 2010 is just to pass  test.table  to the conversion (contains all bytes from 0x00-0xFF) and then check that valid XML results. Since I once had problems with "tidy -q -xml" telling me (incorrectly) that a Non-XML file was XML I just do XML validation by running file to test through identity transform.

$ xsltproc identity.xsl all.xml
<?xml version="1.0"?>
<wrapper>
                                 !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
</wrapper>
$

This test can be done by any XSLT processor (xsltproc above).

There are arbitrarily many ways to create the Non-XML sample file  test.table, stylesheet  gen.xsl  is the (DataPower) XSLT way of doing that.
Of course it does not have to be done by a stylesheet at all, but it can:

 



Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

 

由 HermannSW 2700006U54 于 修改
  • 添加评论 添加评论
  • 编辑
  • 更多操作 v
  • 隔离此条目
通知其他人
notification

发送电子邮件通知

+

隔离此条目

deleteEntry
duplicateEntry

标记为重复项

  • 上一个条目
  • 主页
  • 下一个条目
“博客条目”的订阅源 | “博客评论”的订阅源 | 此条目评论的订阅源