How to Read Xml by Using Id C#
24
Using XML Parser for C
This affiliate contains the following sections:
- Accessing XML Parser for C
- XML Parser for C Features
- XML Parser for C Usage
- XML Parser for C, XSLT (DOM Interface) Usage
- XML Parser for C, Default Behavior
- DOM and SAX APIs
- Invoking XML Parser for C
- Using the Sample Files Included with Your Software
- Running the XML Parser for C Sample Programs
Accessing XML Parser for C
XML Parser for C is provided with Oracle and Oracle Application Server. It is as well available for download from the OTN site: http://otn.oracle.com/tech/xml
It is located in $ORACLE_HOME/xdk/c/parser.
XML Parser for C Features
readme.html in the root directory of the software archive contains release specific information including bug fixes and API additions.
XML Parser for C will check if an XML document is well-formed, and optionally validate it against a DTD. The parser constructs an object tree which tin be accessed through a DOM interface or operate serially via a SAX interface.
You tin can post questions, comments, or bug reports to the XML Discussion Forum at http://otn.oracle.com/tech/xml.
Specifications
Run across Appendix Eastward, "XDK for C: Specifications and Crook Sheets" for a brief listing of XML Parser for C methods and specifications.
Retentivity Allocation
The memory callback functions memcb may be used if you wish to use your own memory allocation. If they are used, all of the functions should exist specified.
The retentivity allocated for parameters passed to the SAX callbacks or for nodes and information stored with the DOM parse tree volition not be freed until ane of the following is done:
-
xmlparse()orxmlparsebuf()is chosen to parse another file or buffer. -
xmlclean()is called. -
xmlterm()is called.
Thread Safe
If threads are forked off somewhere in the midst of the init-parse-term sequence of calls, you will get unpredictable behavior and results.
Data Types Index
Table 24-1 lists the datatypes used in XML Parser for C.
Tabular array 24-1 Datatypes Used in XML Parser for C
| DataType | Description |
|---|---|
| oratext | String pointer |
| xmlctx | Principal XML context |
| xmlmemcb | Retentiveness callback construction (optional) |
| xmlsaxcb | SAX callback structure (SAX but) |
| ub4 | 32-bit (or larger) unsigned integer |
| uword | Native unsigned integer |
Fault Message Files
Fault bulletin files are provided in the mesg/ subdirectory. The messages files also exist in the $ORACLE_HOME/oracore/mesg directory. You may set the surround variable ORA_XML_MESG to point to the absolute path of the mesg/ subdirectory although this not required.
Validation Modes
Available validation modes are described in Chapter xx, "Using XML Parser for Java", "Oracle XML Parsers Back up Four Validation Modes" .
XML Parser for C Usage
Effigy 24-1 describes XML Parser for C calling sequence every bit follows:
-
XMLinit()role initializes the parsing procedure. - The parsed detail can be an XML certificate (file) or string buffer. If the input is an XML document or file, it is parsed using the
xmlparser()role. If the input is a string buffer, it is parsed using thexmlparserbuf()function. - DOM or SAX API:
DOM : If you are using the DOM interface, include the following steps:
- The
xmlparse()orxmlparseBuffer()role calls.getDocumentElement(). If no other DOM functions are being practical, yous can invokexmlterm(). - This optionally calls other DOM functions if required. These are typically Node or impress functions. Information technology outputs the DOM document.
- If complete, the procedure invokes
xmlterm() - You can optionally starting time invoke
xmlclean()to clean upward whatever information structures created during the parse process. You lot would then telephone callxmlterm()
SAX : If you are using the SAX interface, include the following steps:
- Process the results of the parser from
xmlparse()orxmlparseBuf()using callback functions. - Register the callback functions.
- The
- Optionally, apply
xmlclean()to clean upward the memory and structures used during a parse, and go to Step 5. or return to Footstep 2. - Stop the parsing process with
xmlterm()
XML Parser for C usage is further explained in Effigy 24-1.
Parser Calling Sequence
The sequence of calls to the parser tin can be any of the following:
-
xmlinit() - xmlparse()orxmlparsebuf() - xmlterm() -
xmlinit() - xmlparse()orxmlparsebuf() - xmlclean() - xmlparse()orxmlparsebuf() - xmlclean() -... - xmlterm() -
xmlinit() - xmlparse()orxmlparsebuf() - xmlparse()orxmlparsebuf() -... - xmlterm()
Figure 24-1 XML Parser for C Calling Sequence
Text description of the illustration adxml096.gif
XML Parser for C, XSLT (DOM Interface) Usage
Figure 24-2 shows the XML Parser for C, XSLT functionality.
- In that location are 2 inputs to
xmlparse():- The Stylesheet to be practical to the XML certificate
- XML certificate
The output of
xmlparse(), the parsed stylesheet and parsed XML certificate, are sent to thexslprocess()function for processing. -
xmlinit()initializes the XSLT processing.xmlinit()initializes thexslprocess()upshot -
xslprocess()optionally calls other functions, such equally impress functions. You lot tin can see the list of available functions either on OTN or in the Oracle9i XML Reference. - The resultant document (XML, HTML, VML, and so on) is typically sent to an application for further processing.
- The application terminates the XSLT process past declaring
xmlterm(), for the XML document, stylesheet, and concluding upshot.
XML Parser for C's XSLT functionality is illustrated with the following examples:
- XML Parser for C Example xvi: C -- XSLSample.c
- XML Parser for C Example 17: C -- XSLSample.std
Figure 24-ii XML Parser for C: XSLT (DOM Interface) Usage
Text description of the illustration adxml056.gif
XML Parser for C, Default Beliefs
The following is the XML Parser for C default behavior:
- Grapheme ready encoding is UTF-8. If all your documents are ASCII, you lot are encouraged to set the encoding to U.s.a.-ASCII for meliorate performance.
- Letters are printed to stderr unless msghdlr is given.
- A parse tree which tin can be accessed by DOM APIs is built unless saxcb is set to use the SAX callback APIs. Note that whatsoever of the SAX callback functions can be set to Naught if not needed.
- The default behavior for the parser is to bank check that the input is well-formed simply non to bank check whether it is valid. The flag XML_FLAG_VALIDATE can exist fix to validate the input. The default behavior for whitespace processing is to be fully conformant to the XML 1.0 spec, that is, all whitespace is reported back to the awarding only it is indicated which whitespace is ignorable. However, some applications may prefer to set the XML_FLAG_DISCARD_WHITESPACE which will discard all whitespace betwixt an finish-chemical element tag and the following start-element tag.
DOM and SAX APIs
Oracle XML parser for C checks if an XML certificate is well-formed, and optionally validates information technology against a DTD. The parser constructs an object tree which can exist accessed via 1 of the post-obit interfaces:
- DOM interface
- Serially via a SAX interface
These ii XML APIs:
- DOM: Tree-based APIs. A tree-based API compiles an XML document into an internal tree construction, then allows an awarding to navigate that tree using the Document Object Model (DOM), a standard tree-based API for XML and HTML documents.
- SAX: Result-based APIs. An event-based API, on the other hand, reports parsing events (such every bit the start and end of elements) directly to the application through callbacks, and does not unremarkably build an internal tree. The application implements handlers to deal with the different events, much like treatment events in a graphical user interface.
Tree-based APIs are useful for a broad range of applications, but they often put a slap-up strain on system resources, especially if the certificate is large (under very controlled circumstances, it is possible to construct the tree in a lazy fashion to avert some of this problem). Furthermore, some applications need to build their own, different information trees, and it is very inefficient to build a tree of parse nodes, just to map it onto a new tree.
In both of these cases, an consequence-based API provides a simpler, lower-level access to an XML document: yous can parse documents much larger than your available organization memory, and you tin can construct your own data structures using your callback result handlers.
Using the SAX API
To use SAX, an xmlsaxcb structure is initialized with function pointers and passed to the xmlinit() call. A pointer to a user-defined context construction can likewise be included. That context arrow will exist passed to each SAX part.
SAX Callback Structure
The SAX callback construction:
typedef struct { sword (*startDocument)(void *ctx); sword (*endDocument)(void *ctx); sword (*startElement)(void *ctx, const oratext *name, const struct xmlarray *attrs); sword (*endElement)(void *ctx, const oratext *name); sword (*characters)(void *ctx, const oratext *ch, size_t len); sword (*ignorableWhitespace)(void *ctx, const oratext *ch, size_t len); sword (*processingInstruction)(void *ctx, const oratext *target, const oratext *information); sword (*notationDecl)(void *ctx, const oratext *name, const oratext *publicId, const oratext *systemId); sword (*unparsedEntityDecl)(void *ctx, const oratext *name, const oratext *publicId, const oratext *systemId, const oratext *notationName); sword (*nsStartElement)(void *ctx, const oratext *qname, const oratext *local, const oratext *nsp, const struct xmlnodes *attrs); } xmlsaxcb; Using the DOM API
Run across "XML Parser for C Example vii: C -- DOMSample.std" .
Invoking XML Parser for C
XML Parser for C can be invoked in two means:
- By invoking the executable on the command line
- By writing C code and using the supplied APIs
Command Line Usage
The XML Parser for C tin can be called every bit an executable by invoking bin/xml
Table 24-2 lists the command line options.
Table 24-2 XML Parser for C: Command Line Options
| Option | Description |
|---|---|
| -c | Conformance check only, no validation |
| -due east encoding | Specify input file encoding |
| -h | Assist - evidence this usage aid |
| -n | Number - DOM traverse and study number of elements |
| -p | Print document and DTD structures afterward parse |
| -x | Do SAX interface and print document |
| -v | Version - display parser version so leave |
| -w | Whitespace - preserve all whitespace |
Writing C Code to Use Supplied APIs
XML Parser for C can likewise be invoked by writing lawmaking to utilise the supplied APIs. The code must exist compiled using the headers in the include/ subdirectory and linked against the libraries in the lib/ subdirectory. Delight run into the Makefile in the sample/ subdirectory for full details of how to build your program.
Using the Sample Files Included with Your Software
$ORACLE_HOME/xdk/c/parser/sample/ directory contains several XML applications to illustrate how to utilize the XML Parser for C with the DOM and SAX interfaces.
Table 24-3 lists the sample files in sample/ directory.
Table 24-3 XML Parser for C sample/ Files
| sample/ File Name | Description |
|---|---|
| DOMNamespace.c | Source for DOMNamespace program |
| DOMNamespace.std | Expected output from DOMNamespace |
| DOMSample.c | Source for DOMSample program |
| DOMSample.std | Expected output from DOMSample |
| FullDOM.c | Sample usage of DOM interface |
| FullDOM.std | Expected output from FullDOM |
| Brand.bat | Batch file for building sample programs |
| NSExample.xml | Sample XML file using namespaces |
| SAXNamespace.c | Source for SAXNamespace program |
| SAXNamespace.std | Expected output from SAXNamespace |
| SAXSample.c | Source for SAXSample program |
| SAXSample.std | Expected output from SAXSample |
| XSLSample.c | Source for XSLSample program |
| XSLSample.std | Expected output from XSLSample |
| class.xml | XML file that may be used with XSLSample |
| iden.xsl | Stylesheet that may be used with XSLSample |
| cleo.xml | The Tragedy of Antony and Cleopatra XML version of Shakespeare'due south play |
--
Running the XML Parser for C Sample Programs
Building the Sample programs
Alter directories to ..sample/ and read the README file. This will explain how to build the sample programs according to your platform.
Sample Programs
Table 24-4 lists the programs built by the sample files in sample/
Table 24-4 XML Parser for C: Sample Congenital Programs in sample/
| Congenital Program | Description |
|---|---|
| DOMSample | A sample awarding using DOM APIs (shows an outline of Cleopatra, i.east. the XML elements Human action and SCENE). |
| SAXSample [word] | A sample application using SAX APIs. Given a word, shows all lines in the play Cleopatra containing that word. If no word is specified, 'decease' is used. |
| DOMNamespace | Aforementioned every bit SAXNamespace except using DOM interface. |
| SAXNamespace | A sample application using Namespace extensions to SAX API; prints out all elements and attributes of NSExample.xml along with full namespace data. |
| FullDOM | Sample usage of full DOM interface. Exercises all the calls, but does aught too exciting. |
| XSLSample <xmlfile> <xsl ss> | Sample usage of XSL processor. It takes two filenames as input, the XML file and XSL stylesheet |
XML Parser for C Example 1: XML -- class.xml
class.xml is an XML file that inputs XSLSample.c.
<?xml version = "i.0"?> <!DOCTYPE grade [ <!Element course (Proper noun, Dept, Instructor, Student)> <!Element Name (#PCDATA)> <!ELEMENT Dept (#PCDATA)> <!ELEMENT Teacher (Name)> <!Element Educatee (Name*)> ]> <class> <Name>Calculus</Proper noun> <Dept>Math</Dept> <Instructor> <Name>Jim Green</Proper noun> </Teacher> <Student> <Name>Jack</Name> <Proper name>Mary</Name> <Name>Paul</Name> </Student> </course>
XML Parser for C Instance two: XML -- cleo.xml
This XML example inputs DOMSample.c and SAXSample.c.
<?xml version="1.0"?> <!DOCTYPE PLAY [ <!Chemical element PLAY (TITLE, PERSONAE, SCNDESCR, PLAYSUBT, Induct?, PROLOGUE?, ACT+, EPILOGUE?)> <!Element Title (#PCDATA)> <!ELEMENT FM (P+)> <!Chemical element P (#PCDATA)> <!ELEMENT PERSONAE (Championship, (PERSONA | PGROUP)+)> <!ELEMENT PGROUP (PERSONA+, GRPDESCR)> <!Element PERSONA (#PCDATA)> <!ELEMENT GRPDESCR (#PCDATA)> <!Chemical element SCNDESCR (#PCDATA)> <!Chemical element PLAYSUBT (#PCDATA)> <!Element Induct (TITLE, SUBTITLE*, (SCENE+|(Voice communication|STAGEDIR|SUBHEAD)+))> <!Chemical element Act (TITLE, SUBTITLE*, PROLOGUE?, SCENE+, EPILOGUE?)> <!ELEMENT SCENE (Title, SUBTITLE*, (Oral communication | STAGEDIR | SUBHEAD)+)> <!ELEMENT PROLOGUE (Title, SUBTITLE*, (STAGEDIR | Speech)+)> <!ELEMENT EPILOGUE (Championship, SUBTITLE*, (STAGEDIR | SPEECH)+)> <!ELEMENT SPEECH (SPEAKER+, (LINE | STAGEDIR | SUBHEAD)+)> <!ELEMENT SPEAKER (#PCDATA)> <!ELEMENT LINE (#PCDATA | STAGEDIR)*> <!Element STAGEDIR (#PCDATA)> <!Element SUBTITLE (#PCDATA)> <!ELEMENT SUBHEAD (#PCDATA)> ]> <PLAY> <TITLE>The Tragedy of Antony and Cleopatra</Title> <PERSONAE> <Title>Dramatis Personae</Title> <PGROUP> <PERSONA>Mark ANTONY</PERSONA> <PERSONA>OCTAVIUS CAESAR</PERSONA> <PERSONA>Yard. AEMILIUS LEPIDUS</PERSONA> <GRPDESCR>triumvirs.</GRPDESCR> </PGROUP> <PERSONA>SEXTUS POMPEIUS</PERSONA> <PGROUP> <PERSONA>DOMITIUS ENOBARBUS</PERSONA> <PERSONA>VENTIDIUS</PERSONA> <PERSONA>EROS</PERSONA> <PERSONA>SCARUS</PERSONA> <PERSONA>DERCETAS</PERSONA> <PERSONA>DEMETRIUS</PERSONA> <PERSONA>PHILO</PERSONA> <GRPDESCR>friends to Antony.</GRPDESCR> </PGROUP> <PGROUP> <PERSONA>MECAENAS</PERSONA> <PERSONA>AGRIPPA</PERSONA> <PERSONA>DOLABELLA</PERSONA> <PERSONA>PROCULEIUS</PERSONA> <PERSONA>THYREUS</PERSONA> <PERSONA>GALLUS</PERSONA> <PERSONA>MENAS</PERSONA> <GRPDESCR>friends to Caesar.</GRPDESCR> </PGROUP> ... ... <SCNDESCR>SCENE In several parts of the Roman empire.</SCNDESCR> <PLAYSUBT>ANTONY AND CLEOPATRA</PLAYSUBT> <Human activity><Title>ACT I</Championship> <SCENE><Title>SCENE I. Alexandria. A room in CLEOPATRA'southward palace.</TITLE> <STAGEDIR>Enter DEMETRIUS and PHILO</STAGEDIR> <SPEECH> <SPEAKER>PHILO</SPEAKER> <LINE>Nay, just this dotage of our full general's</LINE> <LINE>O'erflows the measure: those his goodly eyes,</LINE> <LINE>That o'er the files and musters of the state of war</LINE> <LINE>Accept glow'd similar plated Mars, now bend, now plow,</LINE> <LINE>The part and devotion of their view</LINE> <LINE>Upon a tawny front: his captain'south centre,</LINE> <LINE>Which in the scuffles of peachy fights hath burst</LINE> <LINE>The buckles on his breast, reneges all temper,</LINE> <LINE>And is become the bellows and the fan</LINE> <LINE>To cool a gipsy'south lust.</LINE> <STAGEDIR>Flourish. Enter ANTONY, CLEOPATRA, her Ladies, the Train, with Eunuchs fanning her</STAGEDIR> <LINE>Look, where they come:</LINE> <LINE>Take but expert notation, and you shall encounter in him.</LINE> <LINE>The triple pillar of the world transform'd</LINE> <LINE>Into a strumpet's fool: behold and see.</LINE> </Spoken communication> <SPEECH> <SPEAKER>CLEOPATRA</SPEAKER> <LINE>If it be love indeed, tell me how much.</LINE> </SPEECH> <Voice communication> <SPEAKER>MARK ANTONY</SPEAKER> <LINE>At that place's beggary in the love that can be reckon'd.</LINE> </Spoken language> <Oral communication> <SPEAKER>CLEOPATRA</SPEAKER> <LINE>I'll set a bourn how far to be beloved.</LINE> </Voice communication> <SPEECH> <SPEAKER>Mark ANTONY</SPEAKER> <LINE>Then must thou needs find out new heaven, new globe.</LINE> </Oral communication> ... ... ... <SPEAKER>DOLABELLA</SPEAKER> <LINE>Here, on her chest,</LINE> <LINE>At that place is a vent of blood and something diddled:</LINE> <LINE>The like is on her arm.</LINE> </SPEECH> <SPEECH> <SPEAKER>Get-go Baby-sit</SPEAKER> <LINE>This is an aspic'due south trail: and these fig-leaves</LINE> <LINE>Accept slime upon them, such as the aspic leaves</LINE> <LINE>Upon the caves of Nile.</LINE> </SPEECH> <Voice communication> <SPEAKER>OCTAVIUS CAESAR</SPEAKER> <LINE>Most likely</LINE> <LINE>That so she died; for her physician tells me</LINE> <LINE>She hath pursued conclusions infinite</LINE> <LINE>Of easy ways to die. Have up her bed;</LINE> <LINE>And bear her women from the monument:</LINE> <LINE>She shall be buried by her Antony:</LINE> <LINE>No grave upon the world shall clip in it</LINE> <LINE>A pair so famous. High events every bit these</LINE> <LINE>Strike those that make them; and their story is</LINE> <LINE>No less in pity than his glory which</LINE> <LINE>Brought them to be lamented. Our army shall</LINE> <LINE>In solemn bear witness attend this funeral;</LINE> <LINE>And and so to Rome. Come, Dolabella, see</LINE> <LINE>High order in this bang-up solemnity.</LINE> </SPEECH> <STAGEDIR>Exeunt</STAGEDIR> </SCENE> </Human action> </PLAY>
XML Parser for C Example three: XSL -- iden.xsl
This case stylesheet can be used to input XSLSample.c.
<?xml version="1.0"?> <!-- Identity transformation --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*|@*|comment()|processing-instruction()|text()"> <xsl:copy> <xsl:use-templates select="*|@*|comment()|processing-didactics()|text()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
XML Parser for C Example 4: XML -- FullDOM.xml (DTD)
This DTD example inputs FullDOM.c.
<!DOCTYPE doc [ <!ELEMENT p (#PCDATA)> <!ATTLIST p xml:space (preserve|default) 'preserve'> <!Annotation notation1 Arrangement "file.txt"> <!Note notation2 PUBLIC "some notation"> <!ELEMENT doc (p*)> <!ENTITY example "<p>An ampersand (&#38;) may be escaped numerically (&#38;#38;) or with a general entity (&amp;).</p>"> ]> <doc xml:lang="foo">&instance;</dr.>
XML Parser for C Example 5: XML -- NSExample.xml
The following example file, NSExample.xml, uses namespaces.
<!DOCTYPE doctor [ <!ELEMENT doc (child*)> <!ATTLIST doc xmlns:nsprefix CDATA #Unsaid> <!ATTLIST doc xmlns CDATA #IMPLIED> <!ATTLIST doc nsprefix:a1 CDATA #IMPLIED> <!ELEMENT child (#PCDATA)> ]> <doc nsprefix:a1 = "v1" xmlns="http://www.w3c.org" xmlns:nsprefix="http://www.oracle.com"> <child> This element inherits the default Namespace of physician. </child> </doc>
XML Parser for C Example half dozen: C -- DOMSample.c
This case contains the C source code for DOMSample.c
/* Copyright (c) Oracle Corporation 1999. All Rights Reserved. */ /* Proper name DOMSample.c - Sample DOM usage DESCRIPTION Sample usage of C XML parser via DOM interface */ #include <stdio.h> #ifndef ORATYPES # include <oratypes.h>
0 Response to "How to Read Xml by Using Id C#"
Postar um comentário