开发者

Using RegEx for Data Transformation

We have a requirement to transform the application specific XML data to a target XSD format specified by government agency. The governme开发者_如何学JAVAnt agency specifies the pattern using regular expression. Please see below for the sample

<! -- Date Type in the format of YYYY-MM-DD -->
<xsd:simpleType name="DateType">
  <xsd:annotation>
    <xsd:documentation>Base type for a date</xsd:documentation>
  </xsd:annotation>
  <xsd:restriction base="xsd:date">
    <xsd:pattern value="[1-9][0-9]{3}\-.*" />
  </xsd:restriction>
</xsd:simpleType>

We are building a custom .NET mapping and transformation solution to support application specific needs. The requirement is to use the regular expression specified in the target XSD to transform the source XML data to meet the pattern required by the target. For example, if the source date is of format mm-dd-yyyy, the program should convert the same to YYYY-MM-DD using the regular expression (1-9][0-9]{3}\-.*")

Likewise there are several RegEx pattern we should leverage based on the data type. Here are our questions:

  1. Is it a general practice to use RegEx for data transformation rather data validation?
  2. If yes, how would be approach this. Is there an established pattern or technique on how to leverage RegEx for data transformation?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜