1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

XML C++ Class Generator Example 2: DTD — Input File to Class Generator, CG.dtd

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.26 MB, 774 trang )


Using the XML C++ Class Generator Examples in sample










C

D

D

E

F



(#PCDATA)>

(#PCDATA)>

attr CDATA #REQUIRED>

(F, F)>

(#PCDATA)>



XML C++ Class Generator Example 3: CG Sample Program

The CG sample program, CG.cpp, does the following:

1.



Initializes the XML parser



2.



Loads the DTD (by parsing the DTD-containing file-- the dummy document

part is ignored)



3.



Creates some objects using the generated classes



4.



Invokes the validation function which verifies that the constructed classes

match the DTD



5.



Writes the constructed document to Sample.xml



//////////////////////////////////////////////////////////////////////////////

// NAME

CG.cpp

// DESCRIPTION Demonstration program for C++ Class Generator usage

//////////////////////////////////////////////////////////////////////////////

#ifndef ORAXMLDOM_ORACLE

# include

#endif

#include

#include "Sample.h"

#define DTD_DOCUMENT"CG.xml"

#define OUT_DOCUMENT"Sample.xml"

int main()

{

XMLParser parser;

Document *doc;

Sample *samp;

B

*b;

D

*d;



XML Class Generator for C++ 19-7



Using the XML C++ Class Generator Examples in sample



E

*e;

F

*f1, *f2;

fstream *out;

ub4

flags = XML_FLAG_VALIDATE;

uword

ecode;

// Initialize XML parser

cout << "Initializing XML parser...\n";

if (ecode = parser.xmlinit())

{

cout << "Failed to initialize parser, code " << ecode << "\n";

return 1;

}

// Parse the document containing a DTD; parsing just a DTD is not

// possible yet, so the file must contain a valid document (which

// is parsed but we're ignoring).

cout << "Loading DTD from " << DTD_DOCUMENT << "...\n";

if (ecode = parser.xmlparse((oratext *) DTD_DOCUMENT, (oratext *)0, flags))

{

cout << "Failed to parse DTD document " << DTD_DOCUMENT <<

", code " << ecode << "\n";

return 2;

}

// Fetch dummy document

cout << "Fetching dummy document...\n";

doc = parser.getDocument();

// Create the constituent parts of a Sample

cout << "Creating components...\n";

b = new B(doc, (String) "Be there or be square");

d = new D(doc, (String) "Dit dah");

d->setattr((String) "attribute value");

f1 = new F(doc, (String) "Formula1");

f2 = new F(doc, (String) "Formula2");

e = new E(doc, f1, f2);

// Create the Sample

cout << "Creating top-level element...\n";

samp = new Sample(doc, b, d, e);

// Validate the construct

cout << "Validating...\n";

if (ecode = parser.validate(samp))



19-8



Oracle9i XML Developer’s Kits Guide - XDK



Using the XML C++ Class Generator Examples in sample



{

cout << "Validation failed, code " << ecode << "\n";

return 3;

}

// Write out doc

cout << "Writing document to " << OUT_DOCUMENT << "\n";

if (!(out = new fstream(OUT_DOCUMENT, ios::out)))

{

cout << "Failed to open output stream\n";

return 4;

}

samp->print(out, 0);

out->close();

// Everything's OK

cout << "Success.\n";

// Shut down

parser.xmlterm();

return 0;

}

// end of CG.cpp



XML Class Generator for C++ 19-9



Using the XML C++ Class Generator Examples in sample



19-10 Oracle9i XML Developer’s Kits Guide - XDK



Part IV

XDK for PL/SQL

These chapters describe how to access and use Oracle XML Developer’s Kit (XDK)

for PL/SQL:

s



Chapter 20, "XML Parser for PL/SQL"



s



Chapter 21, "XSLT Processor for PL/SQL"



s



Chapter 22, "XML Schema Processor for PL/SQL"



s



Chapter 23, "XSU for PL/SQL"

Note: In Oracle9i, XML-SQL Utility (XSU) for PL/SQL is

considered part of the XDK for PL/SQL. In this manual, XSU is

described in Chapter 8, "XML SQL Utility (XSU)".



20

XML Parser for PL/SQL

This chapter contains the following sections:

s



Accessing XML Parser for PL/SQL



s



What’s Needed to Run XML Parser for PL/SQL



s



Using XML Parser for PL/SQL (DOM Interface)



s



Using XML Parser for PL/SQL Examples in the Sample Directory



s



Frequently Asked Questions About the XML Parser for PL/SQL



s



Frequently Asked Questions About Using the DOM API



XML Parser for PL/SQL 20-1



Accessing XML Parser for PL/SQL



Accessing XML Parser for PL/SQL

XML Parser for PL/SQL is provided with Oracle9i and is also available for

download from the OTN site: http://otn.oracle.com/tech/xml.

It is located at $ORACLE_HOME/xdk/plsql/parser



What’s Needed to Run XML Parser for PL/SQL

Appendix B, "XDK for PL/SQL: Specifications" lists the specifications and

requirements for running the XML Parser for PL/SQL. It also includes syntax cheat

sheets.



Using XML Parser for PL/SQL (DOM Interface)

The XML Parser for PL/SQL makes developing XML applications with Oracle9i a

simplified and standardized process. With the PL/SQL interface, Oracle shops

familiar with PL/SQL can extend existing applications to take advantage of XML as

needed.

Since the XML Parser for PL/SQL is implemented in PL/SQL and Java, it can run

"out of the box" on the Oracle9i Java Virtual Machine.

XML Parser for PL/SQL supports the W3C XML 1.0 specification. The goal is to be

100% conformant. It can be used both as a validating or non-validating parser.

In addition, XML Parser for PL/SQL provides the two most common APIs you

need for processing XML documents:

s



W3C-recommended Document Object Model (DOM)



s



XSLT and XPath recommendations



This makes writing custom applications that process XML documents

straightforward in the Oracle9i environment, and means that a standards-compliant

XML parser is part of the Oracle9i platform on every operating system where

Oracle9i is ported.

Figure 20–1 shows the XML Parser for PL/SQL usage and parsing process diagram.



20-2



Oracle9i XML Developer’s Kits Guide - XDK



Using XML Parser for PL/SQL (DOM Interface)



Figure 20–1 XML Parser for PL/SQL Functionality (DOM Interface)



XML Parser for PL/SQL



file name,

varchar buffer,

CLOB

xml input



DTD input



parse()

parseBuffer()

parseClob()



parseDTD()

parseDTDBuffer()

parsedDTDClob()



DTD



getDocument()



getDocType()



setDocType()



other

DOM

functions



Available properties:

· setValidationMode

[default = not]

· setPreserveWhiteSpace

[default = not]

· setDocType

[if input type is a DTD]

· setBaseURL

[refers other locations to

base location if reading

from outside source ]

· showWarnings



newParser



DOM

document



freeDocument()



freeParser()



1.



Make a newParser declaration to begin the parsing process for the XML

document and DTD, if applicable.

Table 20–1 lists available properties for the newParser procedure:



XML Parser for PL/SQL 20-3



Using XML Parser for PL/SQL (DOM Interface)



Table 20–1 XML Parser for PL/SQL: newParser() Properties

Property



Description



setValidationMode



Default = Not



setPreserveWhiteSpace



Default = Not



setDocType



Use if input type is a DTD



setBaseURL



Refers to other locations to the base locations, if reading from

an outside source



showWarnings



Turns warnings on or off.



2.



The XML and DTD can be input as a file, varchar buffer, or CLOB. The XML

input is called by the following procedures:

s



parse() if the XML input is a file



s



parseBuffer() if the XML input is an varchar buffer



s



parserClob() if the XML input is a CLOB



If a DTD is also input, it is called by the following procedures:

s



parseDTD() if the input is an DTD file



s



parseDTDBuffer() if the DTD input is an varchar buffer



s



parserDTDClob() if the DTD input is a CLOB



For the XML Input: For an XML input, the parsed result from Parse(),

ParserBuffer(), or ParserClob() procedures is sent to GetDocument().

3.



getDocument() procedure performs the following:

s



s



Outputs the parsed XML document as a DOM document typically to be

used in a PL/SQL application, or

Applies other DOM functions, if applicable.



4.



Use freeDocument() function to free up the parser and parse the next XML

input



5.



Use freeParser() to free up any temporary document structures created

during the parsing process



For the DTD input: The parsed result from parseDTD(), parseDTDBuffer(), or

parseDTDClob() is used by getDocType() function.

6.



20-4



getDocType() then uses setDocType() to generate a DTD object.



Oracle9i XML Developer’s Kits Guide - XDK



Using XML Parser for PL/SQL Examples in the Sample Directory



7.



The DTD object can be fed into the parser using setDocType() to override the

associated DTD.



See Also:

s



s



s



Oracle9i XML API Reference - XDK and Oracle XML DB for a list

of available optional DOM functions.

Oracle9i XML Database Developer’s Guide - Oracle XML DB , the

chapter on the PL/SQL API for XMLType.



XML Parser for PL/SQL: Default Behavior

The following is the default behavior for XML Parser for PLSQL XML:

s



A parse tree which can be accessed by DOM APIs is built



s



The parser is validating if a DTD is found, otherwise it is non-validating



s



Errors are not recorded unless an error log is specified; however, an application

error will be raised if parsing fails



The types and methods described in this manual are supplied with the PLSQL

package xmlparser().



Using XML Parser for PL/SQL Examples in the Sample Directory

Setting Up the Environment to Run the Sample Programs

The $ORACLE_HOME/xdk/plsql/parser/sample/ directory contains two sample

XML applications:

s



domsample



s



xslsample



These show you how to use XML Parser for PL/SQL.

To run these sample programs carry out the following steps:

1.



Load the PL/SQL parser into the database. To do this, follow the instructions

given in the README file under the lib directory.



2.



You must have the appropriate Java security privileges to read and write from a

file on the file system. To this, first startup SQL*Plus (located typically under



XML Parser for PL/SQL 20-5



Xem Thêm
Tải bản đầy đủ (.pdf) (774 trang)

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×