Home » Developer & Programmer » JDeveloper, Java & XML » Relationships between XML documents
Relationships between XML documents [message #189786] Sun, 27 August 2006 08:26 Go to next message
figrin
Messages: 4
Registered: August 2006
Junior Member
Hi, I am new to Oracle and Oracle XML DB, and I am trying out all the features to see whether XML DB is applicable to my situation at all.

Currently, I am trying to link the relationships between the XML documents.

I have one document that goes something like this:
<XList>
  <X>
    <X_id>x1</X_id>
    <Y_id>y1</Y_id>
    <X_data>x_data1</X_data>
  </X>
  <X>
    <X_id>x2</X_id>
    <Y_id>y2</Y_id>
    <X_data>x_data2</X_data>
  </X>
</XList>


And another document like this:
<YList>
  <Y>
    <Y_id>y1</Y_id>
    <Y_data>y_data1</Y_data>
  </Y>
  <Y>
    <Y_id>y2</Y_id>
    <Y_data>y_data2</Y_data>
  </Y>
</YList>


Is there a way to output a X element out in XML that also fetches the related Y element too, something like (when selecting x_id = x1):
<X>
  <X_id>x1</X_id>
  <Y_id>y1</Y_id>
  <Y>
    <Y_id>y1</Y_id>
    <Y_data>y_data1</Y_data>
  </Y>
  <X_data>x_data1</X_data>
</X>


I have registered the schema and inserted both documents into the same table with a XMLType column, using createSchemaBasedXML during insert. The reason for one generic table is that this needs to be as flexible as possible. Both the XML schema and XML docs/tags are user generated, so there are infinite combinations of related elements users can specify, and no predefine tags. Is there a way I can build a tool that allows users to say /Xlist/X/Y_id points to /Ylist/Y/Y_id so gather the related fragment? I am implement this under PHP (think I may have to change to Java - code just doesn't seem to work with the PHP oci library)

Also, how do you know if your schema is working and the inserted XML is structured and not stored as one big CLOB.

Thanks.
Re: Relationships between XML documents [message #189802 is a reply to message #189786] Sun, 27 August 2006 22:33 Go to previous message
hobbes
Messages: 173
Registered: January 2006
Senior Member
It is possible to maintain reference integrity in XMLType data provided the XML Schemas are well-defined, but if your data model is as generic as you describe then I don't see how you could.

See if this helps: Specifying constraints in Oracle XMLDB

Quote:

Is there a way to output a X element out in XML that also fetches the related Y element too

You can use SQLX functions in a query, with the condition to match /Xlist/X/Y_id with /Ylist/Y/Y_id in the WHERE clause.

Quote:

how do you know if your schema is working and the inserted XML is structured and not stored as one big CLOB.

There are XMLType functions to check schema usage and validity.
- getSchemaURL: Returns the XML schema URL if the input XML is schema-based.
- isSchemaBased: Checks if the input XML is schema based.
- isSchemaValid: Checks if the input XML is valid according to the given schema URL.
- isSchemaValidated: Checks if the input XML has been validated against the schema.

When you store data in an XMLType column then Oracle checks by default whether the XML is well-formed or not. If it is not, insert fails with an XML parsing failure error.
Previous Topic: Problems with DBMS_XMLQUERY
Next Topic: XML for dummies, XLMELEMNT
Goto Forum:
  


Current Time: Mon Nov 25 00:54:04 CST 2024