INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How handle null/empty fields in XML?

How handle null/empty fields in XML?

(OP)
Hi
I have a bunch of XML files that need reading/processing and I've constructed something that uses xmltype, dbms_xmlschema, etc. I've loaded the associated XSD schema into the database using the following:

CODE --> SQL

-- Read the XSD file and load it into an xmltype
-- xtXSD is declared as xmltype
xtXSD := xmltype(dbms_xslprocessor.read2Clob(gccWIFDir, p_vcXSDFilename));

BEGIN
    -- If a schema with this name already exists then get rid of it
    -- i.e. this new schema will overwrite any existing schema
    dbms_xmlschema.deleteSchema(gcvcSchemaURL,
                                dbms_xmlschema.delete_cascade_force);
EXCEPTION
    WHEN schema_doesnt_exist THEN
        NULL;
END;

dbms_xmlschema.registerSchema(schemaurl => gcvcSchemaURL,
                              schemadoc => xtXSD,
                              local     => TRUE,
                              gentypes  => FALSE,
                              genbean   => FALSE,
                              gentables => FALSE); 

When processing the XML files, the following is used:

CODE --> SQL

-- Read the XML file and load it into an xmltype
xtXML := xmltype(dbms_xslprocessor.read2Clob(gccWIFDir, p_vcFilename));

-- Check to make sure the XML contents conform to the schema
xtXML := xtXML.createSchemaBasedXML(gcvcSchemaURL);
xtXML.schemaValidate; 

It all works fine as long as every field in the XML file has a value; if one of the fields has no value (which can legitimately sometimes happen), then the call to schemaValidate above produces the following error:

CODE --> SQL

ORA-31154: invalid XML document
ORA-19202: Error occurred in XML processing
LSX-00009: data missing for type "short"
ORA-06512: at "SYS.XMLTYPE", line 354 

The XSD file contains the following definition for the field that contains a blank value:

CODE --> XML

<xs:element name="index_2">
 <xs:complexType>
  <xs:sequence>
   <xs:element type="xs:string" name="id"/>
   <xs:element type="xs:short" name="value"/>
  </xs:sequence>
 </xs:complexType>
</xs:element> 

...and the section in the XML file that contains the field with no value is:

CODE --> XML

<index_2>
  <id>ICIS_EVENT_ID</id>
  <value />
</index_2> 

Is there any way, either in the XSD or in the way the XML file is processed, to cleanly handle empty values? And by that I mean to somehow indicate that it's OK for a field to contain no value and therefore prevent an error being generated?

Thanks...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close