How to Parse a Xml in Oracle Using Xpath with Xmltype

Topics: XML, Document Object Model, Java Pages: 3 (558 words) Published: September 16, 2010
Old school DOM !

Traditionally Xml parsing was doing using dom objects in Pl/Sql level. This method of parsing XMLs has significant performance hit, even if we left out the many loops that we have to go through to get a value of a single XML element. Enough of Dom, Lest see abut XMLtype.

Oracle 9i and above has this new type of object which is capable of recognizing a XML document end to end.

This is the link to the document.

And if u don’t have time to read it your self I have red it and these are some available functions to extract values safely from a XML. And all the code you see is PLSQL

1. XML is represented as CLOB.
Take the below XML as an example. The xml need (well there might be other ways too) to be provided as clob to the XML type constructor.

l_clob CLOB := '




Don’t Write Blog Posts at work
Please do not do any thing other than work while you are at work


’;2. Lest Start the fire.
Creating XML object.

xml_object SYS.Xmltype;
xml_object:=sys.xmltype.createXML(l_clob);3.Accessing a value of a XML element. If you do this in the proper safe way this is actually three steps. Here are the steps. Check if the Item that you are trying to access exits.

Check if the value on the item is not Null.
Access the value.
IF ( xml_object.existsNode('/ROOT_TAG/HOTLINE') = 1 ) THEN IF( xml_object.extract('/ROOT_TAG/HOTLINE/text()') IS NOT NULL ) THEN xml_data_str := xml_object.extract('/ROOT_TAG/HOTLINE/text()').getStringval(); END IF;

END IF; The xml_object.existsNode just checks whether the element specified in the Xpath exists. If so returns...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Oracle Research Paper
  • Essay on How Oracle Works
  • Oracle EBS Essay
  • Essay about Oracle
  • Essay about oracle
  • Oracle Essay
  • Oracle Essay
  • Rosemarie Parse Essay

Become a StudyMode Member

Sign Up - It's Free