DB2®Connection.RegisterXmlSchema(string, string, string[ ], string[ ]) Method
Registers the XML schema with the database.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public Sub RegisterXmlSchema(
ByVal schema As String,
ByVal name As String,
ByVal ParamArray schemaLocations() As String,
ByVal ParamArray docUrls() As String
) As String
[C#]
public String RegisterXmlSchema(
String schema,
String name,
String[] schemaLocations,
String[] docUrls
);
[C++]
public: String RegisterXmlSchema(
String schema,
String name,
String[] schemaLocations,
String[] docUrls
);
[JScript]
public function RegisterXmlSchema(
schema : String,
name : String,
schemaLocations : String[] *,
docUrls : String[] *
) : String;
Parameters
- schema
- SQL schema name for the XML document. The schema argument can have a NULL value, which indicates that the default SQL schema, as defined in the CURRENT SCHEMA special register, is used.
- name
- Name of the XML schema. When a NULL value is provided for the name argument, a unique value is generated and stored within the XML schema repository (XSR).
- schemaLocations
- String array containing one or more schema locations to be added. The XML schema at index 0 of schemaLocations arrays is taken to be the primary schema.
- docUrls
- String array containing one or more schema documents to be added. The XML schema at index 0 of docUrls arrays is taken to be the primary schema.
Example
Sample book.xsd contains:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="www.samplebookstore.com" >
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
</xs:sequence>
<xs:attribute name="year" type="xs:unsignedShort" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
Sample book.xml contains:
<?xml version="1.0" encoding="utf-8"?>
<book xmlns = "www.samplebookstore.com" year="2000">
<title>Book1</title>
</book>
<book xmlns = "www.samplebookstore.com" year="2001">
<title>Book2</title>
</book>
<book xmlns = "www.samplebookstore.com" year="2002">
<title>Book3</title>
</book>
The following C# code example demonstrate
use of the RegisterXmlSchema method:
using (DB2Connection conn = new DB2Connection(connStr))
{
String xmlDoc =null;
try
{
// Register xml schema
conn.RegisterXmlSchema("NEWTON", "BOOKXSD",
new string[1] { "http://www.test.com/book.xsd" }, new String[1] { "book.xsd"});
TextReader rd = new StreamReader("book.xml");
xmlDoc = rd.ReadToEnd();
// insert XML doc into a table validating it using registered schema
DB2Command cmd = conn.CreateCommand();
cmd.CommandText = "insert into myXmlTable(xmlColumn)
values( xmlvalidate( ? according to xmlschema id NEWTON.BOOKXSD) )";
cmd.Parameters.Add("p1", DB2Type.Xml);
cmd.Parameters[0].Value = xmlDoc;
cmd.ExecuteNonQuery();
//Drop the xml schema
conn.DropXmlSchema("NEWTON", "BOOKXSD");
}
catch (Exception e)
{
// exception handling
}
}
Return value
Function returns the schema name, as supplied or as generated by Db2®.