Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
XML Parsing Question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ExecMan  
View profile  
 More options May 1 2012, 1:50 am
Newsgroups: comp.databases.oracle.server
From: ExecMan <artme...@yahoo.com>
Date: Mon, 30 Apr 2012 22:50:49 -0700 (PDT)
Local: Tues, May 1 2012 1:50 am
Subject: XML Parsing Question
Hi,

I have a procedure that parses an XML file.  It works fine.  I use the
following notations:

v_etf_tab(v_etf_tab.LAST).title  := xslprocessor.valueOf(v_n,'/
ETF_Report/Title');
v_etf_tab(v_etf_tab.LAST).ticker := xslprocessor.valueOf(v_n,'/
ETF_Report/Tickers/Ticker');

However, they have just introduced a new XML file where the TICKER
element can occur more than once:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ETF_Report>
<ReportFile>etf_research_mcg.pdf</ReportFile>
<Title>ETF_RESEARCH</Title>
<ReportType>3</ReportType>
<ReportTypeDescription>Style Box ETF Report</ReportTypeDescription>
<Tickers>
<Ticker>IWP</Ticker>
<Ticker>IVOG</Ticker>
<Ticker>MDYG</Ticker>
<Ticker>RFG</Ticker>
<Ticker>FNY</Ticker>
<Ticker>IJK</Ticker>
<Ticker>PXMG</Ticker>
<Ticker>VOT</Ticker>
<Ticker>JKH</Ticker>
<Ticker>FVL</Ticker>
</Tickers>
</ETF_Report>

How can I go through all the TICKER tags and get those values using
the XML parsing that Oracle provides?  Is there some looping
constructor?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dombrooks  
View profile  
 More options May 1 2012, 5:24 am
Newsgroups: comp.databases.oracle.server
From: dombrooks <dombro...@hotmail.com>
Date: Tue, 1 May 2012 02:24:57 -0700 (PDT)
Local: Tues, May 1 2012 5:24 am
Subject: Re: XML Parsing Question
Use SQL.

with your_xml as
(select xmltype('<?xml version="1.0" encoding="ISO-8859-1" ?>
<ETF_Report>
<ReportFile>etf_research_mcg.pdf</ReportFile>
<Title>ETF_RESEARCH</Title>
<ReportType>3</ReportType>
<ReportTypeDescription>Style Box ETF Report</ReportTypeDescription>
<Tickers>
<Ticker>IWP</Ticker>
<Ticker>IVOG</Ticker>
<Ticker>MDYG</Ticker>
<Ticker>RFG</Ticker>
<Ticker>FNY</Ticker>
<Ticker>IJK</Ticker>
<Ticker>PXMG</Ticker>
<Ticker>VOT</Ticker>
<Ticker>JKH</Ticker>
<Ticker>FVL</Ticker>
</Tickers>
</ETF_Report>') xml
from dual)
select extractvalue(value(x), '/Ticker') ticker
from   xmltable('/*/Tickers/Ticker'  
       passing (select xml  
                from   your_xml)) x;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ExecMan  
View profile  
 More options May 1 2012, 9:37 am
Newsgroups: comp.databases.oracle.server
From: ExecMan <artme...@yahoo.com>
Date: Tue, 1 May 2012 06:37:18 -0700 (PDT)
Local: Tues, May 1 2012 9:37 am
Subject: Re: XML Parsing Question
On May 1, 4:24 am, dombrooks <dombro...@hotmail.com> wrote:

Will this work is "your_xml" is read from a file?  I am parsing XML
files.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dombrooks  
View profile  
 More options May 1 2012, 10:06 am
Newsgroups: comp.databases.oracle.server
From: dombrooks <dombro...@hotmail.com>
Date: Tue, 1 May 2012 07:06:47 -0700 (PDT)
Local: Tues, May 1 2012 10:06 am
Subject: Re: XML Parsing Question
Yes / It depends.

The above is just a demo using with/your_xml to simulate the source of a valid doc/snippet of xml.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ExecMan  
View profile  
 More options May 1 2012, 10:46 am
Newsgroups: comp.databases.oracle.server
From: ExecMan <artme...@yahoo.com>
Date: Tue, 1 May 2012 07:46:19 -0700 (PDT)
Local: Tues, May 1 2012 10:46 am
Subject: Re: XML Parsing Question
On May 1, 9:06 am, dombrooks <dombro...@hotmail.com> wrote:

> Yes / It depends.

> The above is just a demo using with/your_xml to simulate the source of a valid doc/snippet of xml.

Well, being new at this XML thingy I'm not sure I am getting the
code.  Here is what I currently have in place.  This works fine,
except now we are getting multiple of the TICKER node, and I need to
loop and process those.

  v_xml_id := OPEN_FILES(p_xml_dir,p_xml_files,'r');

  LOOP
    BEGIN
      UTL_FILE.GET_LINE(v_xml_id,v_xml_file);

      v_parser := xmlparser.newParser;
      dbms_xmlparser.setBaseDir(v_parser,p_xml_dir);
      xmlparser.parse(v_parser,v_xml_file);
      v_doc := xmlparser.getDocument(v_parser);
      xmlparser.freeParser(v_parser);

      v_nl := xslprocessor.selectNodes(xmldom.makeNode(v_doc),'/
ETF_Report');

      -- Loop through the document and create a new record in table
collection
      FOR v_rec IN 0 .. dbms_xmldom.getLength(v_nl) - 1 LOOP
        BEGIN
          v_n := dbms_xmldom.item(v_nl, v_rec);

          v_etf_tab.EXTEND;
          v_etf_tab(v_etf_tab.LAST).title  :=
xslprocessor.valueOf(v_n,'/ETF_Report/Title');
          v_etf_tab(v_etf_tab.LAST).ticker :=
xslprocessor.valueOf(v_n,'/ETF_Report/Tickers/Ticker');

          DBMS_OUTPUT.PUT_LINE('HERE: ' ||
v_etf_tab(v_etf_tab.LAST).title);
          DBMS_OUTPUT.PUT_LINE('HERE: ' ||
v_etf_tab(v_etf_tab.LAST).ticker);

          EXCEPTION
          WHEN OTHERS THEN
             NULL;
        END;
      END LOOP;

      EXCEPTION
      WHEN NO_DATA_FOUND THEN
        UTL_FILE.FCLOSE_ALL;
        EXIT;
    END;

    xmldom.freeDocument(v_doc);
  END LOOP;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »