我使用DataStage将以下XML用于数据库。 DataStage允许我指定要从xml中获取并插入db表的特定字段的XPATH。从下面的xml可以看出,有些标签是空的或不存在。我需要一个XPATH表达式,可以查询标签是空的还是不存在的,如果它是,那么我希望XPATH返回一个NULL,以便可以将NULL插入到该字段的db表中,例如在Entity_ID 2222上,Postal_Code不存在,所以我希望db表中的Postal_Code字段填充DB NULL。同样,在Entity_ID 1111上,City标签存在但是为空,我希望City db表字段中为NULL。任何帮助是极大的赞赏。提前谢谢。
<?xml version="1.0"?>
<NewDataSet>
<Entity_Data msdata:rowOrder="0" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" diffgr:id="Entity Data1" diffgr:hasChanges="inserted" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Entity_ID>1111</Entity_ID>
<Name>EntityName</Name>
<Street>EntityStreet</Street>
<City/>
<State>EntityState</State>
<Postal_Code>12345</Postal_Code>
</Entity_Data>
<Entity_Data msdata:rowOrder="1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" diffgr:id="Entity Data2" diffgr:hasChanges="inserted" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Entity_ID>2222</Entity_ID>
<Name>EntityName</Name>
<Street>EntityStreet</Street>
<City>EntityCity</City>
<State>EntityState</State>
<Phone>555-555-5555</Phone>
</Entity_Data>
<Entity_Data msdata:rowOrder="4" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" diffgr:id="Entity Data5" diffgr:hasChanges="inserted" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Entity_ID>3333</Entity_ID>
<Name>EntityName</Name>
<Street>EntityStreet</Street>
<City>EntityCity</City>
<State>EntityState</State>
<Postal_Code>22222</Postal_Code>
</Entity_Data>
</NewDataSet>
答案 0 :(得分:0)
我在DataStage中解决了这个问题,方法是将所有输出行的XML Input阶段'nullable'属性设置为'yes'(除了用于重复的键之外)。