•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the XML, XSLT and XPATH section within the Software Development category of DaniWeb, a massive community of 456,573 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,565 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our XML, XSLT and XPATH advertiser: Programming Forums
Views: 6736 | Replies: 49
![]() |
•
•
Join Date: Oct 2007
Posts: 76
Reputation:
Rep Power: 2
Solved Threads: 0
DB2 stores information about XML Schemas in a system catalog view SYSCAT.XSROBJECTS. This view can be queried to retrieve information like the object schema, object name, target namespace, and schema location. The actual schema documents are stored in catalog SYSCAT.XSROBJECTCOMPONENT. The SYSCAT.XSROBJECTS catalog view contains 1 row per XML Schema. On the other hand, SYSCAT.XSROBJECTCOMPONENT catalog has 1 row per schema document.
You can use following queries to get the information:
SELECT objectschema, objectname, targetnamespace, schemalocation FROM syscat.xsrobjects
SELECT objectschema, objectname, targetnamespace, schemalocation from syscat.xsrobjectcomponents
You can use following queries to get the information:
SELECT objectschema, objectname, targetnamespace, schemalocation FROM syscat.xsrobjects
SELECT objectschema, objectname, targetnamespace, schemalocation from syscat.xsrobjectcomponents
•
•
Join Date: Oct 2007
Posts: 76
Reputation:
Rep Power: 2
Solved Threads: 0
A registered schema can be dropped by using Drop XSRObject command. The schema repository does not have a notion of individual schema documents. It only has a notion of an XML Schema, which is a collection of 1 or more schema documents. Thus, to drop an XSR Object implies deleting all schema documents associated with that XSR Object.
•
•
Join Date: Oct 2007
Posts: 76
Reputation:
Rep Power: 2
Solved Threads: 0
Below example generates an "employee" element for each employee. The employee element is associated with XML namespace "urn:bo', which is bound to prefix "bo". The element contains attributes for names and a hiredate subelement.
SELECT e.empno, XMLSERIALIZE(XMLELEMENT(NAME "bo:employee",
XMLNAMESPACES('urn:bo' as "bo"), XMLATTRIBUTES(e.lastname, e.firstnme), XMLELEMENT(NAME "bo:hiredate", e.hiredate)) AS CLOB(50)) FROM employee e where e.edlevel = 12;
The result of the query would be similar to the following result:
<bo:employee xmlns:bo="urn:bo" LASTNAME="PARKER" FIRSTNME="JOHN">
<bo:hiredate>198-5-3</bo:hiredate></bo:employee><bo:employee
xmlns:bo="urn:bo"
LASTNAME="SETRIGHT"FIRSTNME="MAUDE"><bo:hiredate>1964-9-12</bo:hiredate></bo:employee>
Another example: generate two elements for each employee using XMLFOREST. The first "lastname" element is associated with the default namespace "http://hr.org", and the second "job" element is associated with XML namespace "http://fed.gov", which is bound to prefix "d".
SELECT empno, XMLSERIALIZE(XMLFOREST(XMLNAMESPACES(DEFAULT 'http://hr.org', 'http://fed.gov' AS "d"),lastname, job AS "d:job") AS CLOB(50)) FROM employee where edlevel = 12;
The result of the query would be similar to the following result:
<LASTNAME xmlns=http://hr.org xmlns:d="http://fed.gov
">PARKER</LASTNAME><d:job xmlns="http://hr.org" xmlns:d="http://fed.gov">OPERATOR</d:job>
<LASTNAME xmlns="http://hr.org"
xmlns:d="http://fed.gov">SETRIGHT</LASTNAME><d:job xmlns="http://hr.org" xmlns:d="http://fed.gov">OPERATOR</d:job>
MTK can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at
http://www-1.ibm.com/support/docview...id=swg27009230.
SELECT e.empno, XMLSERIALIZE(XMLELEMENT(NAME "bo:employee",
XMLNAMESPACES('urn:bo' as "bo"), XMLATTRIBUTES(e.lastname, e.firstnme), XMLELEMENT(NAME "bo:hiredate", e.hiredate)) AS CLOB(50)) FROM employee e where e.edlevel = 12;
The result of the query would be similar to the following result:
<bo:employee xmlns:bo="urn:bo" LASTNAME="PARKER" FIRSTNME="JOHN">
<bo:hiredate>198-5-3</bo:hiredate></bo:employee><bo:employee
xmlns:bo="urn:bo"
LASTNAME="SETRIGHT"FIRSTNME="MAUDE"><bo:hiredate>1964-9-12</bo:hiredate></bo:employee>
Another example: generate two elements for each employee using XMLFOREST. The first "lastname" element is associated with the default namespace "http://hr.org", and the second "job" element is associated with XML namespace "http://fed.gov", which is bound to prefix "d".
SELECT empno, XMLSERIALIZE(XMLFOREST(XMLNAMESPACES(DEFAULT 'http://hr.org', 'http://fed.gov' AS "d"),lastname, job AS "d:job") AS CLOB(50)) FROM employee where edlevel = 12;
The result of the query would be similar to the following result:
<LASTNAME xmlns=http://hr.org xmlns:d="http://fed.gov
">PARKER</LASTNAME><d:job xmlns="http://hr.org" xmlns:d="http://fed.gov">OPERATOR</d:job>
<LASTNAME xmlns="http://hr.org"
xmlns:d="http://fed.gov">SETRIGHT</LASTNAME><d:job xmlns="http://hr.org" xmlns:d="http://fed.gov">OPERATOR</d:job>
MTK can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at
http://www-1.ibm.com/support/docview...id=swg27009230.
•
•
Join Date: Oct 2007
Posts: 76
Reputation:
Rep Power: 2
Solved Threads: 0
You can’t validate XML document against DTDs; DTDs validation not supported. You can validate your XML document against XML schemas only. You can still insert documents that contain a DOCTYPE or that refer to DTDs.
There are tools available, such as those in IBM Rational Application Developer that help you generate XML schemas from various sources, including DTDs, existing tables, or XML documents.
Before you can validate, you must register your XML schema with the built-in XML schema repository (XSR). This process involves registering each XML schema document that makes up the XML schema. Once all XML schema documents have been successfully registered, you must complete the registration. One method of registering an XML schema is through commands.
Register and complete registration of the posample.customer XML schema as follows, providing the absolute path to the sqllib/samples/xml directory on your system:
REGISTER XMLSCHEMA 'http://posample.org' FROM 'file:///<c:/sqllib/samples/xml>customer.xsd' AS posample.customer COMPLETE
You can verify that the XML schema was successfully registered by using follow query:
SELECT OBJECTSCHEMA, OBJECTNAME FROM SYSCAT.XSROBJECTS
MTK can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at
http://www-1.ibm.com/support/docview...id=swg27009230.
There are tools available, such as those in IBM Rational Application Developer that help you generate XML schemas from various sources, including DTDs, existing tables, or XML documents.
Before you can validate, you must register your XML schema with the built-in XML schema repository (XSR). This process involves registering each XML schema document that makes up the XML schema. Once all XML schema documents have been successfully registered, you must complete the registration. One method of registering an XML schema is through commands.
Register and complete registration of the posample.customer XML schema as follows, providing the absolute path to the sqllib/samples/xml directory on your system:
REGISTER XMLSCHEMA 'http://posample.org' FROM 'file:///<c:/sqllib/samples/xml>customer.xsd' AS posample.customer COMPLETE
You can verify that the XML schema was successfully registered by using follow query:
SELECT OBJECTSCHEMA, OBJECTNAME FROM SYSCAT.XSROBJECTS
MTK can be downloaded at
http://www-306.ibm.com/software/data/db2/migration/mtk/. More information can be found at
http://www-1.ibm.com/support/docview...id=swg27009230.
•
•
Join Date: Oct 2007
Posts: 76
Reputation:
Rep Power: 2
Solved Threads: 0
The following INSERT statement inserts a new XML document into the Info column of the Customer table, only if the document is valid according to the posample.customer XML schema previously registered.
INSERT INTO Customer(Cid, Info) VALUES (1003, XMLVALIDATE (XMLPARSE (DOCUMENT
'<customerinfo xmlns="http://posample.org" Cid="1003">
<name>Robert Shoemaker</name>
<addr country="Canada">
<street>1596 Baseline</street>
<city>Aurora</city>
<prov-state>Ontario</prov-state>
<pcode-zip>N8X 7F8</pcode-zip>
</addr>
<phone type="work">905-555-7258</phone>
<phone type="home">416-555-2937</phone>
<phone type="cell">905-555-8743</phone>
<phone type="cottage">613-555-3278</phone>
</customerinfo>' PRESERVE WHITESPACE )
ACCORDING TO XMLSCHEMA ID posample.customer ))
XMLVALIDATE operates on XML data. Because the XML document in this example is passed as character data, and character data can only be assigned directly to XML in INSERT, UPDATE, or DELETE statements, the XMLPARSE function must be used in this case. The XMLPARSE function parses its argument as an XML document and returns an XML value.
To verify that the validation and insert were successful, query the Info column:
SELECT Info FROM Customer
This query should return three XML documents, one of which is the document just inserted.
INSERT INTO Customer(Cid, Info) VALUES (1003, XMLVALIDATE (XMLPARSE (DOCUMENT
'<customerinfo xmlns="http://posample.org" Cid="1003">
<name>Robert Shoemaker</name>
<addr country="Canada">
<street>1596 Baseline</street>
<city>Aurora</city>
<prov-state>Ontario</prov-state>
<pcode-zip>N8X 7F8</pcode-zip>
</addr>
<phone type="work">905-555-7258</phone>
<phone type="home">416-555-2937</phone>
<phone type="cell">905-555-8743</phone>
<phone type="cottage">613-555-3278</phone>
</customerinfo>' PRESERVE WHITESPACE )
ACCORDING TO XMLSCHEMA ID posample.customer ))
XMLVALIDATE operates on XML data. Because the XML document in this example is passed as character data, and character data can only be assigned directly to XML in INSERT, UPDATE, or DELETE statements, the XMLPARSE function must be used in this case. The XMLPARSE function parses its argument as an XML document and returns an XML value.
To verify that the validation and insert were successful, query the Info column:
SELECT Info FROM Customer
This query should return three XML documents, one of which is the document just inserted.
![]() |
•
•
•
•
•
•
•
•
DaniWeb XML, XSLT and XPATH Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Newbie question, schema, complex types and unordered multiple elemets (XML, XSLT and XPATH)
- XML Schema Question (RSS, Web Services and SOAP)
- WSDL file EDITING (VB.NET)
- SOAP n00b (RSS, Web Services and SOAP)
- XML Transformations (XML, XSLT and XPATH)
- automated database design (Database Design)
- IListSource does not contain any data sources (ASP.NET)
- parsing error (XML file-java-schema) (Java)
- Active Directory (Windows NT / 2000 / XP / 2003)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: Bug in XPathAPI.selectSingleNode ???
- Next Thread: Java Script Menu with XML menu entries.


Linear Mode