p_row_selector值对于apex_data_parser.parse应该是什么?

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

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

然后这是我作为结果得到的:

p_row_selector值对于apex_data_parser.parse应该是什么?

然而,我期望看到所有子标签在其父标签中作为单独的列。这是否可行?如果可以,如何设置我的行选择器以一次获取(对于此示例)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 -->

&lt;Document&gt;
  &lt;group_1&gt;
    &lt;group_1_1&gt;
      &lt;MsgId&gt;x&lt;/MsgId&gt;
      &lt;CreDtTm&gt;2023-05-01T16:20:06.770+00:00&lt;/CreDtTm&gt;
      &lt;MsgPgntn&gt;
        &lt;PgNb&gt;1&lt;/PgNb&gt;
        &lt;LastPgInd&gt;richtig&lt;/LastPgInd&gt;
      &lt;/MsgPgntn&gt;
    &lt;/group_1_1&gt;
    &lt;group_1_2&gt;
      &lt;Id&gt;36&lt;/Id&gt;
      &lt;Acct&gt;
        &lt;Id&gt;
          &lt;Othr&gt;
            &lt;Id&gt;xxx&lt;/Id&gt;
          &lt;/Othr&gt;
        &lt;/Id&gt;
        &lt;Ownr&gt;
          &lt;Id&gt;
            &lt;OrgId&gt;
              &lt;AnyBIC&gt;yyy&lt;/AnyBIC&gt;
            &lt;/OrgId&gt;
          &lt;/Id&gt;
        &lt;/Ownr&gt;
      &lt;/Acct&gt;
      &lt;Bal&gt;
        &lt;Tp&gt;
          &lt;CdOrPrtry&gt;
            &lt;Cd&gt;aaa&lt;/Cd&gt;
          &lt;/CdOrPrtry&gt;
        &lt;/Tp&gt;
        &lt;Amt Ccy=&quot;EUR&quot;&gt;0.00&lt;/Amt&gt;
        &lt;CdtDbtInd&gt;CRDT&lt;/CdtDbtInd&gt;
        &lt;Dt&gt;
          &lt;Dt&gt;2023-01-01&lt;/Dt&gt;
        &lt;/Dt&gt;
      &lt;/Bal&gt;
      &lt;Bal&gt;
        &lt;Tp&gt;
          &lt;CdOrPrtry&gt;
            &lt;Cd&gt;bbb&lt;/Cd&gt;
          &lt;/CdOrPrtry&gt;
        &lt;/Tp&gt;
        &lt;Amt Ccy=&quot;EUR&quot;&gt;0.00&lt;/Amt&gt;
        &lt;CdtDbtInd&gt;CRDT&lt;/CdtDbtInd&gt;
        &lt;Dt&gt;
          &lt;Dt&gt;2023-01-02&lt;/Dt&gt;
        &lt;/Dt&gt;
      &lt;/Bal&gt;
    &lt;/group_1_2&gt;
  &lt;/group_1&gt;
&lt;/Document&gt;

<!-- 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                     =&gt; x.blob_content,
                  p_add_headers_row             =&gt; &#39;Y&#39;,
                  p_row_selector                =&gt; &#39;/Document/group_1/group_1_2&#39;,                  
                  p_store_profile_to_collection =&gt; &#39;FILE_PARSER_COLLECTION&#39;,
                  p_file_name                   =&gt; x.filename)) y
 where x.name = :P1_NEW

and this is what I'm getting as result

p_row_selector值对于apex_data_parser.parse应该是什么?

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(&#39;Document/group_1&#39;
	passing x.xml_file
	columns 
		MsgId varchar2(20) path &#39;group_1_1&#39;,
		CreDtTm varchar2(50) path &#39;group_1_1&#39;,
		PgNb varchar2(20) path &#39;group_1_1/MsgPgntn&#39;,
		bal xmltype path &#39;group_1_2/Bal&#39;
		) y,
	xmltable(&#39;/.&#39;
	passing y.bal
	columns 
		cdorprtry varchar2(20) path &#39;group_1_2/Bal/Tp&#39;)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"

huangapple
  • 本文由 发表于 2023年5月13日 15:36:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241593.html
匿名

发表评论

匿名网友

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

确定