英文:
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
<?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" />
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 = 'path=PRINTING/HDR/PYMT_LINE +
case=any +
allowextra=yes +
allowmissing=yes +
doc=file +
datasubf=value';
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(以及其他内容)的有用文章
英文:
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
答案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)
<?xml version="1.0" encoding="ISO-8859-1"?>
<PRINTING>
<HDR CW_DEPT_CD="736" CW_FILE_ID="W105B22355001" />
</PRINTING>
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 = 'path=PRINTING/HDR +
case=any +
doc=file +
datasubf=value';
xml-into hdr %xml('xmltest.xml' : options);
return;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论