XML-INTO与RPGLE数据结构的问题

huangapple go评论45阅读模式
英文:

XML-INTO issue with RPGLE data structure

问题

工作中第一次尝试将XML读取到RPG程序中。我没有将数据读取到我的DS中,当我尝试查看子字段时,出现"标识符不存在"的错误。

这是样本XML的一部分:

<?xml version="1.0" encoding="ISO-8859-1"?>
<PRINTING>
    <HDR CW_DEPT_CD="736" CW_FILE_ID="W105B22355001" CW_UNIT_CD="D736" BANK_ACCT_CD="GA" PYMT_DT="12/12/2022" PROC_DT="12/12/2022" CHK_FRMT="GENZ" CHK_FRMT_DSCR="Generic Z-Fold" DISB_CAT="SAM" DISB_CAT_DSCR="Sealed Agency Mailed" DISB_HDLG_CD="null" DISB_HDLG_DSCR="null" STD_TXT="null" BANK_ACCN_NO="936836402" BANK_NO="083000137" DEPT_NM="Department For Community Based Services" UNIT_NM="Department for Community Based Services" PERMIT_NO="null" CNTAC_CD="76" EXTR_AD_1="ATTN: DAFM/TWIST" EXTR_AD_2="275 East Main Street 3W-C" EXTR_AD_3="null" EXTR_CITY="Frankfort" EXTR_ST="KY" ST_NM="null" EXTR_ZIP="40621" EXTR_CTRY="null" EXTR_EMAIL_AD="null" PH_NO="502-564-3427" PH_EXT="null" FAX_NO="null" />
</PRINTING>

这是程序的一部分:

dcl-ds HDR DIM(10) Qualified;
    CW_DEPT_CD char(4);
    CW_FILE_ID char(20);
    CW_UNIT_CD char(4);
    BANK_ACCT_CD char(4);
    ...更多字段

    dcl-ds PYMT_LINE;
        LN_NO char(6);
        VEN_CUST_CD char(20);
        LGL_NM char(60);
        ...更多字段
    end-ds PYMT_LINE;
end-ds HDR;

Eval options = 'path=PRINTING/HDR/PYMT_LINE +
                case=any +
                allowextra=yes +
                allowmissing=yes +
                doc=file +
                datasubf=value';

xml-into HDR
    %XML(Filename:options);

我感激任何反馈。

谢谢

尝试了我能找到的一切。

希望这对你有所帮助。

英文:

Working on a program to read XML to RPG for the first time. I'm not getting the data into my DS and when I try to view the subfields I get Identifier does not exist.

This is part of the sample xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt; 
&lt;PRINTING&gt; 
&lt;HDR CW_DEPT_CD=&quot;736&quot; CW_FILE_ID=&quot;W105B22355001&quot; 
 CW_UNIT_CD=&quot;D736&quot; BANK_ACCT_CD=&quot;GA&quot; PYMT_DT=&quot;12/12/2022&quot; 
 PROC_DT=&quot;12/12/2022&quot; CHK_FRMT=&quot;GENZ&quot; CHK_FRMT_DSCR=&quot;Generic Z-Fold&quot; 
 DISB_CAT=&quot;SAM&quot; DISB_CAT_DSCR=&quot;Sealed Agency Mailed&quot; 
 DISB_HDLG_CD=&quot;null&quot; DISB_HDLG_DSCR=&quot;null&quot; STD_TXT=&quot;null&quot; 
 BANK_ACCN_NO=&quot;936836402&quot; BANK_NO=&quot;083000137&quot; 
 DEPT_NM=&quot;Department For Community Based Services&quot; 
 UNIT_NM=&quot;Department for Community Based Services&quot; PERMIT_NO=&quot;null&quot; 
 CNTAC_CD=&quot;76&quot; EXTR_AD_1=&quot;ATTN: DAFM/TWIST&quot; 
 EXTR_AD_2=&quot;275 East Main Street 3W-C&quot; EXTR_AD_3=&quot;null&quot; 
 EXTR_CITY=&quot;Frankfort&quot; EXTR_ST=&quot;KY&quot; ST_NM=&quot;null&quot; EXTR_ZIP=&quot;40621&quot; 
 EXTR_CTRY=&quot;null&quot; EXTR_EMAIL_AD=&quot;null&quot; PH_NO=&quot;502-564-3427&quot; 
 PH_EXT=&quot;null&quot; FAX_NO=&quot;null&quot; /&gt;

And here is the program piece.

  dcl-ds HDR DIM(10) Qualified;
     CW_DEPT_CD char(4);         
     CW_FILE_ID  char(20);       
     CW_UNIT_CD  char(4);        
     BANK_ACCT_CD  char(4); ...more fields 

     dcl-ds PYMT_LINE;       
        LN_NO      char(6);    
        VEN_CUST_CD   char(20);
        LGL_NM    char(60);  ... more fields
     end-ds PYMT_LINE;                     
                                        
  end-ds HDR;      
  Eval options = &#39;path=PRINTING/HDR/PYMT_LINE +                     
                  case=any +                                
                  allowextra=yes +                          
                  allowmissing=yes +                        
                  doc=file +                                
                  datasubf=value&#39;;                          
                                                             
  xml-into HDR                                                     
           %XML(Filename:options);   

I appreciate any feedback.

Thanks

Tried everything that I could find.

答案1

得分: 1

你的路径是PRINTING/HDR/PYMT_LINE,但你的数据结构与HDR匹配。

路径应该指向与你的数据结构匹配的元素,所以我认为它应该只是路径=PRINTING/HDR。

在你的XML-INTO可以处理该XML时,使用allowextra=yes和allowmissing=yes是可以的,但这可能会使开发新的XML-INTO变得困难。使用这些选项时,数据结构可以完全不匹配XML文档。

所以当我开发一个新的XML-INTO时,我不会编写这些选项。相反,我会创建一个临时版本的XML,它与数据结构完全匹配。然后当我让它正常工作时,我可能会添加allowextra=yes,如果我认为XML可能有额外的元素。

但我几乎从不添加allowmissing=yes。相反,我使用countprefix选项。以下是一个讨论allowmissing与countprefix(以及其他内容)的有用文章 XML-INTO与RPGLE数据结构的问题

英文:

You have path=PRINTING/HDR/PYMT_LINE, but your data structure matches HDR.

The path should point to the element that matches your data structure, so I think it should just be path=PRINTING/HDR.

Using allowextra=yes and allowmissing=yes is ok when you have your XML-INTO working with that XML, but it can make it difficult to develop a new XML-INTO. With those options, the data structure can completely mismatch the XML document.

So when I'm development a new XML-INTO, I don't code those options. Instead, I make a temporary version of the XML that matches the data structure exactly. Then when I have it working, I might add allowextra=yes if I think the XML might have extra elements.

But I almost never add allowmissing=yes. Instead, I use the countprefix option. Here's a useful article that discusses allowmissing vs countprefix (among other things XML-INTO与RPGLE数据结构的问题

答案2

得分: 0

我认为你应该从一个简化的XML和数据结构开始,使其能够工作。然后逐渐添加回XML数据和子字段以进行匹配。

例如,从这个XML开始(我将其保存在一个名为xmltest.xml的文件中):

<?xml version="1.0" encoding="ISO-8859-1"?>
<PRINTING>
    <HDR CW_DEPT_CD="736" CW_FILE_ID="W105B22355001" />
</PRINTING>

以及这个RPG程序:

dcl-ds HDR Qualified;
   CW_DEPT_CD char(4);
   CW_FILE_ID char(20);
end-ds;
dcl-s options varchar(100);

Eval options = 'path=PRINTING/HDR +
                case=any +
                doc=file +
                datasubf=value';

xml-into hdr %xml('xmltest.xml' : options);
return;

希望这能帮助你开始工作。

英文:

I think you should start with a reduced form of your XML and your data structure and get that working. And then gradually add back the XML data and the subfields to match.

For example, start with this XML (I have this in a file xmltest.xml)

&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;        
&lt;PRINTING&gt;                                         
&lt;HDR CW_DEPT_CD=&quot;736&quot; CW_FILE_ID=&quot;W105B22355001&quot; /&gt;
&lt;/PRINTING&gt;    

And this RPG program:

dcl-ds HDR Qualified;                      
   CW_DEPT_CD char(4);                     
   CW_FILE_ID  char(20);                   
end-ds;                                    
dcl-s options varchar(100);                
                                           
Eval options = &#39;path=PRINTING/HDR +        
                case=any +                 
                doc=file +                 
                datasubf=value&#39;;           
                                           
xml-into hdr %xml(&#39;xmltest.xml&#39; : options);
return;                                  

huangapple
  • 本文由 发表于 2023年6月16日 00:49:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483872.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定