This discussion is archived
3 Replies Latest reply: Jun 26, 2012 1:36 AM by odie_63 RSS

how to extract xml comments

945609 Newbie
Currently Being Moderated
Hi,

I have loaded XML files into my table of XML Type . I have comments in XML file. This comments are important to us and I want to extract this comments . How can we extract the comments present in XML file. I was not able to find any function which can do it.

Thanks,
Ramesh.
  • 1. Re: how to extract xml comments
    odie_63 Guru
    Currently Being Moderated
    Hi Ramesh,

    First of all, instead of posting three times in different forums, why not provide relevant details such as database version and a sample XML?

    Generally, XML comments are not meant to be extracted.
    If they contain so important data then most likely that data should be stored in regular element or attribute nodes.

    Here's an example using XQuery though :
    SQL> create table tmp_xml of xmltype;
     
    Table created
     
    SQL> 
    SQL> insert into tmp_xml values (
      2   xmltype('<root>
      3  <!-- this is a comment -->
      4  <item/>
      5  <!-- this is another comment -->
      6  </root>')
      7  );
     
    1 row inserted
     
    SQL> 
    SQL> select x.comment_text
      2  from tmp_xml t
      3     , xmltable(
      4         '/descendant::comment()'
      5         passing t.object_value
      6         columns comment_text varchar2(200) path '.'
      7       ) x
      8  ;
     
    COMMENT_TEXT
    --------------------------------------------------------------------------------
     this is a comment
     this is another comment
     
  • 2. Re: how to extract xml comments
    945609 Newbie
    Currently Being Moderated
    Hi,

    Thanks for the reply. It solved my issue.

    Wondering, I want not able to find information about this in any document at all.

    Thanks and Regards,
    Ramesh.
  • 3. Re: how to extract xml comments
    odie_63 Guru
    Currently Being Moderated
    That's XQuery/XPath 2.0 language, you should be able to find some general tutorials on the Internet.

    Oracle implementation of it is described in the documentation :
    http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb_xquery.htm#CBAGCBGJ

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points