Perl Cd Bookshelf [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Cd Bookshelf [Electronic resources] - نسخه متنی

Mark V. Scardina, Ben ChangandJinyu Wang

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








Best Practices



If you need to accept XML data and store it in the database, the first thing that you should consider is whether your application requires preserving the XML structure in the database. As we discussed in Chapter 8, you need to evaluate the pros and cons of the XML storage options and analyze how the storage affects the retrieving and updating of the XML data. Additionally, you sometimes need to choose a particular XML storage model in order to support receiving XML in the presence of evolving XML schemas.


After selecting the right XML storage model for your application, the following sections provide some guidelines of what you need to know when storing XML in Oracle Database 10g.



Handling Document Type Definitions



Although DTDs are not used to define the storage structure for XMLTypes, Oracle XML DB resolves all the DTD definitions and entities defined or referenced in the inserted XML document. This is performed during the inserting process of XMLType when all the incoming XML documents are parsed. In this process, all the entities, including external or internal entities defined in DTDs, are resolved. This means that all the entities are replaced with their actual values and hence the original entity references are lost.


If you would like to preserve these entity references, you have to store the XML in CLOBs, instead of CLOB XMLTypes. You then can create temporary XMLTypes from these CLOBs whenever you need to resolve all the entities and use the XML content.



Creating XML Schema–based XMLTypes



You can create XML Schema–based XMLTypes using the XMLType construction functions or the XMLType.CreateXML() function. However, when you are using these functions to create XML Schema–based XMLTypes, the XML documents have to contain the XML SchemaLocation attributes. Sometimes XML documents do not contain such attributes. How can you create an XML Schema–based XMLType without changing the original XML document?


As you have seen in Chapter 8, you can use the XMLType.CreateSchemaBasedXML function and specify the URL of the XML schema as follows:


INSERT INTO product(id, name, description)
VALUES('xdk', 'XML Developer's Kit',
XMLTYPE('<DESCRIPTION><KEYWORD>xdk</KEYWORD> is a set of
standards-based utilities that helps to build
<KEYWORD>XML</KEYWORD> applications. It contains XDK Java
Components, XDK C Components and XDK C++ Components.
</DESCRIPTION>').CreateSchemaBasedXML('http://xmlns.oracle.com/
xml/content.xsd'));


The URL http://xmlns.oracle.com/xml/content.xsd is the registered URL of the XML schema, and it will be used to store the product DESCRIPTION.



Specifying Namespaces



If a stored XML document has namespaces, all of the XML queries on the document have to be namespace-qualified because the <Namespace:Element> is not the same as <Element> in XML. Both the XMLType.existsNode()and the XMLType.extract() functions allow the user to specify the namespace in the second parameter as follows:


MEMBER FUNCTION existsNode(xpath in varchar2, nsmap in varchar2)
RETURN number deterministic
MEMBER FUNCTION extract(xpath IN varchar2, nsmap IN varchar2)
RETURN XMLType deterministic


In this case, the XPath needs to use fully qualified XML names, which contain the element name and its namespace. For example, you can insert an XML document with two namespace declarations into XMLTypes as follows:


CREATE TABLE temp (doc XMLType);
DECLARE
v_temp XMLType;
BEGIN
v_temp:= XMLType.createXML('<foo xmlns="http://www.example.com"
xmlns:xsd="http://www.w3c.org/2001/XMLSchema">
<foo_type xsd:type="date">03-11-1998</foo_type>
</foo>');
INSERT INTO temp VALUES(v_temp);
END;


To query the document, you can define the namespace and its prefix in the second parameter of the XMLType.extract() function and qualify the XPath using the prefix, as shown in the following SQL query:


SELECT a.doc.extract('/a:foo/a:foo_type',
'xmlns:a="http://www.example.com"')
FROM temp a;


The result is


<foo_type xmlns="http://www.example.com"
xmlns:xsd="http://www.w3c.org/2001/XMLSchema"
xsd:type="date">03-11-1998</foo_type>






Note


If you do not use the namespace-qualified name in the XPath after providing namespaces, you will get an ORA-31013: Invalid XPath expression error.




If you have multiple namespaces, you can list them in the second parameter of the XMLType.existsNode() and the XMLType.extract() function and separate them with white spaces, as shown in the following example:


SELECT a.doc.extract('/a:foo/a:lastupdate/@b:type',
'xmlns:a="http://www.example.com"
xmlns:b="http://www.w3c.org/2001/XMLSchema"') AS result
FROM temp a;
RESULT
----------------------------------------
date


/ 218