現在、PL/SQL を使用して一部の XML を解析する際に問題が発生しています。基本的に、既存の関数によって提供される clob 変数に格納されている XML があります。clob を xmltype に変換するために使用する xmltype の新しい変数を作成します。次に、この新しい xmltype 変数の内容をループ処理して、各タグの内容を取り出して独自の div に出力しようとします。ただし、私のコードは現在、すべてのタグの内容を 1 つの div に出力するだけで、まったくループしていないという印象を与えます。
XML 構造は次のとおりです (明らかに、より多くの内部タグが入れ子になっています)。
<?xml version="1.0" encoding="UTF-8"?>
<results>
<return>
<createDate> Date 1 Here </createDate>
<description> Description 1 here </description>
</return>
<return>
<createDate> Date 2 Here </createDate>
<description> Description 2 here </description>
</return>
</results>
そして、ループスルーに使用している PLSQL は次の場所にあります。
-- parsing : Parse the xml and wrap description content in a html div
l_html_build := '<!DOCTYPE html><html><head></head><body>';
l_parse_xml := (xmltype(l_xml_response));
l_parse_xml_index := 1;
while l_parse_xml.existsNode('//description[' || To_Char(l_parse_xml_index) || ']') > 0
loop
l_html_build := l_html_build || '<div class="description">';
l_html_build := l_html_build || (xmltype(l_xml_response).extract('//description[' || To_Char(l_parse_xml_index)
|| ']/text()').getclobval());
l_html_build := l_html_build || '</div>';
l_html_build := replace(l_html_build,'<','<');
l_html_build := replace(l_html_build,'>','>');
l_html_build := replace(l_html_build,'&lt;','');
l_html_build := replace(l_html_build,'&gt;','');
l_html_build := replace(l_html_build,'&nbsp;',' ');
l_html_build := l_html_build ||'</body></html>';
l_parse_xml_index := l_parse_xml_index + 1;
end loop;
一部のパラメータと変数の説明は、次のとおりです。
l_xml_response clob; -- XML from another function is stored here
l_html_build clob; -- Used as a variable to store the output to be sent to the page
l_parse_xml xmltype; -- l_xml_response content is passed into this xmltype variable which is used for parsing
l_parse_xml_index number; -- Used as an index to assist with looping through the tags
出力は次のとおりです。
<div class = "description">
Description 1 here Description 2 here
</div>
それがいつあるべきか:
<div class = "description">
Description 1 here
</div>
<div class = "description">
Description 2 here
</div>
私は貿易によるhtml/css/php/javascriptプログラマーであり、PL/SQLを実際に行ったことがないため、どんな助けも大歓迎です(そして、私の上司は実際には役に立たないトレーニングを提供していません) .
前もって感謝します!