英文:
what should be my p_row_selector value for apex_data_parser.parse?
问题
我正在尝试解析APEX18上的XML文件。
XML结构如下:
<Document>
<group_1>
<group_1_1>
<MsgId>x</MsgId>
<CreDtTm>2023-05-01T16:20:06.770+00:00</CreDtTm>
<MsgPgntn>
<PgNb>1</PgNb>
<LastPgInd>richtig</LastPgInd>
</MsgPgntn>
</group_1_1>
<group_1_2>
<Id>36</Id>
<Acct>
<Id>
<Othr>
<Id>xxx</Id>
</Othr>
</Id>
<Ownr>
<Id>
<OrgId>
<AnyBIC>yyy</AnyBIC>
</OrgId>
</Id>
</Ownr>
</Acct>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>aaa</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">0.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2023-01-01</Dt>
</Dt>
</Bal>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>bbb</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">0.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2023-01-02</Dt>
</Dt>
</Bal>
</group_1_2>
</group_1>
</Document>
我通过:P1_NEW(文件浏览器)项目上传此文件,然后尝试使用以下查询选择它:
select line_number, col001, col002, col003, col004, col005
from apex_application_temp_files x,
table(apex_data_parser.parse(
p_content => x.blob_content,
p_add_headers_row => 'Y',
p_row_selector => '/Document/group_1/group_1_2',
p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
p_file_name => x.filename)) y
where x.name = :P1_NEW
然后这是我作为结果得到的:
然而,我期望看到所有子标签在其父标签中作为单独的列。这是否可行?如果可以,如何设置我的行选择器以一次获取(对于此示例)Id、Acct、Ownr、Bal...等值?
如果要将子标签的值作为单独的列返回,您可以尝试使用XPath表达式,将其逐个选择出来,然后将其用作列别名。例如:
select
apex_xml.getnodevalue(xmltype(x.blob_content), '/Document/group_1/group_1_2/Id') as Id,
apex_xml.getnodevalue(xmltype(x.blob_content), '/Document/group_1/group_1_2/Acct') as Acct,
apex_xml.getnodevalue(xmltype(x.blob_content), '/Document/group_1/group_1_2/Ownr') as Ownr,
apex_xml.getnodevalue(xmltype(x.blob_content), '/Document/group_1/group_1_2/Bal') as Bal
from apex_application_temp_files x
where x.name = :P1_NEW
这将为您提供每个子标签的单独列,您可以根据需要添加更多的列。
英文:
I am trying to parse an XML file on APEX18
XML structure is like this:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<Document>
<group_1>
<group_1_1>
<MsgId>x</MsgId>
<CreDtTm>2023-05-01T16:20:06.770+00:00</CreDtTm>
<MsgPgntn>
<PgNb>1</PgNb>
<LastPgInd>richtig</LastPgInd>
</MsgPgntn>
</group_1_1>
<group_1_2>
<Id>36</Id>
<Acct>
<Id>
<Othr>
<Id>xxx</Id>
</Othr>
</Id>
<Ownr>
<Id>
<OrgId>
<AnyBIC>yyy</AnyBIC>
</OrgId>
</Id>
</Ownr>
</Acct>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>aaa</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">0.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2023-01-01</Dt>
</Dt>
</Bal>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>bbb</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">0.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2023-01-02</Dt>
</Dt>
</Bal>
</group_1_2>
</group_1>
</Document>
<!-- end snippet -->
I upload this file via :P1_NEW (file browser) item, then try to select it with below query
select line_number, col001, col002, col003, col004, col005
from apex_application_temp_files x,
table(apex_data_parser.parse(
p_content => x.blob_content,
p_add_headers_row => 'Y',
p_row_selector => '/Document/group_1/group_1_2',
p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
p_file_name => x.filename)) y
where x.name = :P1_NEW
and this is what I'm getting as result
however, I am expecting to see all the sub-tags within their parents as seperate columns. Is it futile? if it can be done, how can I set my row selector to get (for this sample) Id, Acct, Ownr, Bal... values in different columns at once?
答案1
得分: 0
我已成功解析文件,并能够在 APEX 中使用 XMLTYPE 将其显示出来,根据 @Koen 的建议。
当我尝试将查询适应上面的示例 XML 时,可能在查询中弄乱了,但思路是相同的。这是我所做的:
select *
from
my_table x,
xmltable('Document/group_1'
passing x.xml_file
columns
MsgId varchar2(20) path 'group_1_1',
CreDtTm varchar2(50) path 'group_1_1',
PgNb varchar2(20) path 'group_1_1/MsgPgntn',
bal xmltype path 'group_1_2/Bal'
) y,
xmltable('/.'
passing y.bal
columns
cdorprtry varchar2(20) path 'group_1_2/Bal/Tp')z
为了在同一行中获取嵌套节点的内容,我不得不将每个父节点作为另一个具有重复标签的 XMLTYPE 进行连接。在这个示例中是 "group_1_2/Bal"。
英文:
I've managed to parse the file and able to show it in APEX by using XMLTYPE, upon @Koen's point.
I probably messed the query while I was trying to adapt it to the sample XML above, but the idea is the same. Here is what I did:
select *
from
my_table x,
xmltable('Document/group_1'
passing x.xml_file
columns
MsgId varchar2(20) path 'group_1_1',
CreDtTm varchar2(50) path 'group_1_1',
PgNb varchar2(20) path 'group_1_1/MsgPgntn',
bal xmltype path 'group_1_2/Bal'
) y,
xmltable('/.'
passing y.bal
columns
cdorprtry varchar2(20) path 'group_1_2/Bal/Tp')z
In order to get nested nodes' content in the same row, I had to join each parent node as another XMLTYPE that has repeating TAGs within. In this sample it was "group_1_2/Bal"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论