Home » Developer & Programmer » JDeveloper, Java & XML » select current node threw xmlquery
select current node threw xmlquery [message #460059] Wed, 09 June 2010 08:01 Go to next message
b_52globemaster
Messages: 51
Registered: July 2005
Member
hi,

i got a xml data formatted with that form:
<content>
 <section>
 <section_id>34</section_id>
  <section_name>Data</section_name>
	<block>
	 <block_id>34</block_id>
	 <block_name>RData</block_name>
	  <block>
		<relevantPublications>
		 <relevantPublicationsTitle>title</relevantPublicationsTitle>
		  <doc>
			 <nom>somefile</nom>
			 <size>156382</size>
			 <date>2010-05-25 04:46:57</date>
		  </doc>
		 </relevantPublications>
	  </block>
	  </block>
	</section>
</content>


i would to go true the stream and look if there a section_id with the value 34 if it the case it should return the corresponding node /section


any help with that please ?
Re: select current node threw xmlquery [message #460073 is a reply to message #460059] Wed, 09 June 2010 08:34 Go to previous messageGo to next message
Michel Cadot
Messages: 59405
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> with 
  2    data as (
  3      select xmltype('
  4  <content>
  5   <section>
  6   <section_id>34</section_id>
  7    <section_name>Data</section_name>
  8   <block>
  9    <block_id>34</block_id>
 10    <block_name>RData</block_name>
 11     <block>
 12    <relevantPublications>
 13     <relevantPublicationsTitle>title</relevantPublicationsTitle>
 14      <doc>
 15      <nom>somefile</nom>
 16      <size>156382</size>
 17      <date>2010-05-25 04:46:57</date>
 18      </doc>
 19     </relevantPublications>
 20     </block>
 21     </block>
 22   </section>
 23  </content>
 24  ') xmldata
 25      from dual
 26    )
 27  select extract(xmldata,'//section') v
 28  from data,
 29       TABLE(XMLSequence(extract(xmldata,'//section'))) x
 30  where extractvalue(value(x),'/section/section_id') = 34
 31  /
V
--------------------------------------------------------------------------------
<section><section_id>34</section_id><section_name>Data</section_name><block><blo
ck_id>34</block_id><block_name>RData</block_name><block><relevantPublications><r
elevantPublicationsTitle>title</relevantPublicationsTitle><doc><nom>somefile</no
m><size>156382</size><date>2010-05-25 04:46:57</date></doc></relevantPublication
s></block></block></section>

Regards
Michel
Re: select current node threw xmlquery [message #460092 is a reply to message #460059] Wed, 09 June 2010 10:03 Go to previous messageGo to next message
b_52globemaster
Messages: 51
Registered: July 2005
Member
Hi Michel,

thanks a lot , one more thing ? how to force o return only the return 34 because not it return all of them.
with 
      data as (
       select xmltype('
    <content>
    <section>
     <section_id>34</section_id>
      <section_name>Data</section_name>
     <block>
      <block_id>34</block_id>
     <block_name>RData</block_name>
      <block>
     <relevantPublications>
      <relevantPublicationsTitle>title</relevantPublicationsTitle>
       <doc>
       <nom>somefile</nom>
       <size>156382</size>
       <date>2010-05-25 04:46:57</date>
       </doc>
      </relevantPublications>
      </block>
      </block>
    </section>
    <section>
     <section_id>389</section_id>
      <section_name>Bdat</section_name>
     <block>
      <block_id>324</block_id>
     <block_name>RData</block_name>
      <block>
     <relevantPublications>
      <relevantPublicationsTitle>title</relevantPublicationsTitle>
       <doc>
       <nom>somefile</nom>
       <size>156382</size>
       <date>2010-05-25 04:46:57</date>
       </doc>
      </relevantPublications>
      </block>
      </block>
    </section>
   </content>
   ') xmldata
       from dual
     )
   select extract(xmldata,'//section') v
   from data,
        TABLE(XMLSequence(extract(xmldata,'//section'))) x
   where extractvalue(value(x),'/section/section_id') = 34



it return
Quote:

<section><section_id>34</section_id><section_name>Data</section_name><block><block_id>34</block_id><block_name>RData</block_name ><block><relevantPublications><relevantPublicationsTitle>title</relevantPublicationsTitle><doc><nom>somefile</nom><size>156382 </size><date>2010-05-25 04:46:57</date></doc></relevantPublications></block></block></section><section><section_id>389</section_id><section_name>Bdat </section_name><block><block_id>324</block_id><block_name>RData</block_name><block><relevantPublications><relevantPublicationsTitle >title</relevantPublicationsTitle><doc><nom>somefile</nom><size>156382</size><date>2010-05-25 04:46:57</date></doc></relevantPublications></block></block></section>

and thanks
Re: select current node threw xmlquery [message #460094 is a reply to message #460092] Wed, 09 June 2010 10:19 Go to previous message
Michel Cadot
Messages: 59405
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
With all the examples I gave you maybe you should try to find by yourself and come back with your tries or solution before I still spent hours to find answers for you.
It would be nice if I can see that my time was spent learning you something and not just doing your work.

Regards
Michel
Previous Topic: How can i delete a node from a pl/sql variable of xmltype
Next Topic: How to pass XML Parameter
Goto Forum:
  


Current Time: Mon Oct 20 17:12:06 CDT 2014

Total time taken to generate the page: 0.13175 seconds