使用 XML GENERATE 函数调整生成的名称

Adjust the generated name with XML GENERATE Function

如果我有这样的 COBOL 结构:

(结构应该是这样的,因为我必须使用XML Generate Function转换它,变量名只是样本)

01. MyData.
02. Corp-Entity
    03. Corp-Branch1.
        04. Address.
            05. AddressLine1 PIC X(20).
            05. AddressLine2 PIC X(20).
            05. PostalCode   PIC 9(05).
        04. PIC-Entity.
            05. Address.
                06. AddressLine1 PIC X(20).
                06. AddressLine2 PIC X(20).
                06. PostalCode   PIC 9(05).

如何移动 05. AddressLine1 中的值?

如果我写这段代码:

move valueAddressLine1 to AddressLine1 
                       in Address
                       in Corp-Brach1
                       in MyData

但此代码对 06. AddressLine1

有效
move valueAddressLine1 to AddressLine1 
                       in Address
                       in PIC-Entity

错误信息: "AddressLine1 of Address of PIC-Entity" 不是唯一定义的名称。
无法根据上下文确定要使用的定义。对名称的引用已被丢弃。

预注:

  • 由于关卡数字后的句点,该代码将无法使用,去掉这些。
  • 要拥有唯一的名称,您不需要完整的资格。例如以下是好的:
            move valueAddressLine1 to AddressLine1 
                                   in PIC-Entity

答案:

在这种情况下:"fix" COBOL 端使用可以唯一访问的名称,在大多数情况下通过它的 "parent" 项目,而这不可能像你的 04 Address 通过使用不同的名称(例如 04 corp-address).

如您希望在 XML 中使用此结构,您可以使用 NAME 短语,如 IBM 的文档 XML element name and attribute name formation 所说:

In the XML documents that are generated from identifier-2, the XML element names and attribute names are obtained from the NAME phrase if specified; otherwise they are derived from the names of the data item specified by identifier-2 and from any eligible data-names that are subordinate to identifier-2.

IBM 在 XML GENERATE statement 上的文档有这方面的详细信息。对于给定的样本和假定的 2 个公司分支机构:

           XML GENERATE variable-name
               FROM Corp-Entity
               NAME OF corp-address in corp-branch1 IS 'Address'
                       corp-address in corp-branch2 IS 'Address'