Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

DBE_XMLPARSER

Updated on 2024-08-20 GMT+08:00

API Description

The DBE_XMLPARSER API is used to deserialize XML character strings and convert the character strings that store XML documents to document nodes. Table 1 lists all APIs supported by the DBE_XMLPARSER advanced package.

The XMLParser data type can be used to store XMLParser data. The maximum number of XMLParser data records that can be stored is 16777215. The XMLPARSER data type can parse and create the DOMDocument node according to the input character string. The advanced package also provides the corresponding set and get APIs to perform operations on the constraint attributes of the parsing process.

NOTE:

When the DBE_XMLPARSER advanced package is used in the database whose character set is set to SQL_ASCII, an error is reported if characters beyond the ASCII range are input.

The DBE_XMLPARSER advanced package supports only the A-compatible mode.

Table 1 DBE_XMLPARSER parameters

API

Description

DBE_XMLPARSER.FREEPARSER

Frees a parser.

DBE_XMLPARSER.GETDOCUMENT

Obtains the parsed document node.

DBE_XMLPARSER.GETVALIDATIONMODE

Obtains the validation attribute.

DBE_XMLPARSER.NEWPARSER

Creates a parser instance.

DBE_XMLPARSER.PARSEBUFFER

Parses the VARCHAR string.

DBE_XMLPARSER.PARSECLOB

Parses the CLOB string.

DBE_XMLPARSER.SETVALIDATIONMODE

Sets the validation attribute.

  • DBE_XMLPARSER.FREEPARSER

    Frees a given parser object.

    The stored procedure prototype of DBE_XMLPARSER.FREEPARSER is as follows:

    1
    2
       DBE_XMLPARSER.FREEPARSER (
         p     IN     parser);
    
    Table 2 DBE_XMLPARSER.FREEPARSER parameters

    Parameter

    Description

    p

    Parser object

    Example:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    -- Create a parser and then release it.
    DECLARE
      l_parser dbe_xmlparser.parser;   
      BEGIN
      l_parser := dbe_xmlparser.newparser;
    -- Directly release the l_parser instance.
      dbe_xmlparser.freeparser(l_parser);
    END;
    /
    

    Result: The operation is successful.

  • DBE_XMLPARSER.GETDOCUMENT

    Returns the root node of the DOM tree document constructed by the parser. This function can be called only after the document is parsed.

    The prototype of the DBE_XMLPARSER.GETDOCUMENT function is as follows:

    1
    2
    3
    DBE_XMLPARSER.GETDOCUMENT (
      p     IN     parser) 
     RETURN DOMDocument;
    
    Table 3 DBE_XMLPARSER.GETDOCUMENT parameters

    Parameter

    Description

    p

    Parser object

    NOTE:
    • If the GETDOCUMENT function has no input parameter, an error is reported.
    • If the parser parameter of the GETDOCUMENT function is null, NULL is returned.
    • If the parser input by the GETDOCUMENT function has not parsed any document, NULL is returned.
    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    -- Create a parser to parse character strings and print the obtained document.
    DECLARE
      l_parser dbe_xmlparser.parser;
      l_doc dbe_xmldom.domdocument;
      buffer varchar2 := 
    '<?xml version="1.0" encoding="UTF-8"?>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Donot forget me this weekend!</body>
    </note>';
      buffer2 varchar2;
      BEGIN
      l_parser := dbe_xmlparser.newparser;
    -- The l_parser parses the character string and obtains the DOMDocument node through GETDOCUMENT.
      dbe_xmlparser.PARSEBUFFER(l_parser, buffer);
      l_doc := dbe_xmlparser.getdocument(l_parser);
    -- Print the content in l_doc.
      dbe_xmldom.writetobuffer(l_doc, buffer2);
      RAISE NOTICE '%', buffer2;
    
      dbe_xmlparser.freeparser(l_parser);
      dbe_xmldom.freedocument(l_doc);
    END;
    /
    

    Execution result:

    1
    2
    3
    4
    5
    6
    7
    NOTICE:  <?xml version="1.0" encoding="UTF-8"?>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Donot forget me this weekend!</body>
    </note>
    
  • DBE_XMLPARSER.GETVALIDATIONMODE

    Obtains the parsing validation mode of a specified parser. If DTD validation is enabled, TRUE is returned. Otherwise, FALSE is returned.

    The prototype of the DBE_XMLPARSER.GETVALIDATIONMODE function is as follows:

    1
    2
    3
    DBE_XMLPARSER.GETVALIDATIONMODE (
      p     IN     parser) 
     RETURN BOOLEAN;
    
    Table 4 DBE_XMLPARSER.GETVALIDATIONMODE parameters

    Parameter

    Description

    p

    Parser object

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    -- Create a parser and use GETVALIDATIONMODE to check whether the parser validation mode is enabled.
    DECLARE 
      l_parser dbe_xmlparser.parser;
    BEGIN
      l_parser := dbe_xmlparser.newparser();
        if (dbe_xmlparser.GETVALIDATIONMODE(l_parser) = true) then
     RAISE NOTICE 'validation';
        else 
        RAISE NOTICE 'no validation';
      end if;
      dbe_xmlparser.freeparser(l_parser);
    END;
    /
    

    Execution result:

    1
    NOTICE:  validation
    
  • DBE_XMLPARSER.NEWPARSER

    Creates a parser object and returns a new parser instance.

    The prototype of the DBE_XMLPARSER.NEWPARSER function is as follows:

    1
    2
    DBE_XMLPARSER.NEWPARSER 
     RETURN Parser;
    
    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    -- Create a parser to parse character strings and then free the parser.
    DECLARE
      -- Create a parser.
      l_parser dbe_xmlparser.parser;
      l_doc dbe_xmldom.domdocument;
      buffer varchar2(1000) := 
        '<?xml version="1.0" encoding="UTF-8"?>
        <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Donot forget me this weekend!</body>
        </note>';
      buffer2 varchar2(1000);
      BEGIN
      l_parser := dbe_xmlparser.newparser;
      -- Parse the document and create a new DOM document.
      dbe_xmlparser.PARSEBUFFER(l_parser, buffer);
    
      dbe_xmlparser.freeparser(l_parser);
    END;
    /
    

    Result: The operation is successful.

  • DBE_XMLPARSER.PARSEBUFFER

    Parses XML documents stored in strings.

    The stored procedure prototype of DBE_XMLPARSER.PARSEBUFFER is as follows:

    1
    2
    3
    DBE_XMLPARSER.PARSEBUFFER (
       p     IN     parser,
       doc   IN VARCHAR2);
    
    Table 5 DBE_XMLPARSER.PARSEBUFFER parameters

    Parameter

    Description

    p

    Parser object

    doc

    A string that stores XML documents

    NOTE:
    • The maximum length of a character string that can be parsed by the PARSEBUFFER function is 32767. If the length exceeds the maximum, an error is reported.
    • Different from the database A, this database supports only UTF-8 in terms of character encoding, and version can only be set to 1.0. If versions 1.0 to 1.9 are parsing, a warning appears but the execution is normal. For versions later than 1.9, an error is reported.
    • DTD validation differences:
      • !ATTLIST to type (CHECK|check|Check) "Ch..." reports an error because the default value "Ch..." is not an enumerated value in the brackets. However, the database A does not report this error.
      • <!ENTITY baidu "www.baidu.com">...... &Baidu;&writer reports an error because the letters are case-sensitive. Baidu cannot correspond to baidu. However, the database A does not report this error.
    • Namespace validation difference: Undeclared namespace tags are parsed. However, the database A reports an error.
    • Difference in parsing XML predefined entities: &apos; and &quot; are parsed and translated into ' and ". However, predefined entities in database A are not translated into characters.
    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    -- Create a parser to parse character strings and print the obtained document.
    DECLARE
      l_parser dbe_xmlparser.parser;
      l_doc dbe_xmldom.domdocument;
      buffer varchar2 := 
    '<?xml version="1.0" encoding="UTF-8"?>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Donot forget me this weekend!</body>
    </note>';
      buffer2 varchar2;
      BEGIN
      l_parser := dbe_xmlparser.newparser;
      dbe_xmlparser.PARSEBUFFER(l_parser, buffer);
      l_doc := dbe_xmlparser.getdocument(l_parser);
     
      dbe_xmldom.writetobuffer(l_doc, buffer2);
      RAISE NOTICE '%', buffer2;
    
      dbe_xmlparser.freeparser(l_parser);
      dbe_xmldom.freedocument(l_doc);
    END;
    /
    

    Execution result:

    1
    2
    3
    4
    5
    6
    7
    NOTICE:  <?xml version="1.0" encoding="UTF-8"?>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Donot forget me this weekend!</body>
    </note>
    
  • DBE_XMLPARSER.PARSECLOB

    Parses XML documents stored in a CLOB.

    The stored procedure prototype of DBE_XMLPARSER.PARSECLOB is as follows:
    1
    2
    3
    DBE_XMLPARSER.PARSECLOB (
       p     IN     parser,
       doc   IN CLOB);
    
    Table 6 DBE_XMLPARSER.PARSECLOB parameters

    Parameter

    Description

    p

    Parser object

    doc

    A CLOB that stores XML documents

    NOTE:
    • PARSECLOB cannot parse CLOBs greater than or equal to 2 GB.
    • Different from the database A, this database supports only UTF-8 in terms of character encoding, and version can only be set to 1.0. If versions 1.0 to 1.9 are parsing, a warning appears but the execution is normal. For versions later than 1.9, an error is reported.
    • DTD validation differences:
      • !ATTLIST to type (CHECK|check|Check) "Ch..." reports an error because the default value "Ch..." is not an enumerated value in the brackets. However, the database A does not report this error.
      • <!ENTITY baidu "www.baidu.com">...... &Baidu;&writer reports an error because the letters are case-sensitive. Baidu cannot correspond to baidu. However, the database A does not report this error.
    • Namespace validation difference: Undeclared namespace tags are parsed. However, the database A reports an error.
    • Difference in parsing XML predefined entities: &apos; and &quot; are parsed and translated into ' and ". However, predefined entities in database A are not translated into characters.
    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    -- Create a parser to parse character strings and print the obtained document.
    DECLARE
      
      l_clob clob :=
     '<?xml version="1.0" encoding="UTF-8"?>
      <note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>this weekend!</body>
      </note>';
      -- Create a parser.
      l_parser dbe_xmlparser.parser;
      l_doc dbe_xmldom.domdocument;
      buffer varchar2(1000);
      BEGIN
      l_parser := dbe_xmlparser.newparser;
      -- Parse the document and create a new DOM document.
      dbe_xmlparser.parseclob(l_parser, l_clob);
      l_doc := dbe_xmlparser.getdocument(l_parser);
      dbe_xmldom.writetobuffer(l_doc, buffer);
      RAISE NOTICE '%',buffer;
     
      dbe_xmlparser.freeparser(l_parser);
      dbe_xmldom.freedocument(l_doc);
     
      END;
      /
    

    Execution result:

    1
    2
    3
    4
    5
    6
    7
    NOTICE:  <?xml version="1.0" encoding="UTF-8"?>
    <note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>this weekend!</body>
    </note>
    
  • DBE_XMLPARSER.SETVALIDATIONMODE

    Sets the parsing validation mode of a specified parser.

    The stored procedure prototype of DBE_XMLPARSER.SETVALIDATIONMODE is as follows:

    1
    2
    3
    DBE_XMLPARSER.SETVALIDATIONMODE(
      p     IN     parser) 
      yes   IN BOOLEAN);
    
    Table 7 DBE_XMLPARSER.SETVALIDATIONMODE parameters

    Parameter

    Description

    p

    Parser object

    yes

    Mode to be set:
    • TRUE: DTD validation is enabled.
    • FALSE: DTD validation is disabled.
    NOTE:
    • If the input parameter yes of the SETVALIDATIONMODE function is null, the parsing validation mode of the parser is not changed.
    • By default, the DTD validation is enabled during parser initialization.

    Example 1:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    -- Create a parser. The XML character string to be parsed does not match the DTD format.
    -- If setValidationMode is set to false, the string can be parsed. If setValidationMode is set to true, an error is reported during parsing.
    DECLARE
      l_clob clob := 
     '<!DOCTYPE note [
     <!ELEMENT note (to,from,heading,body)>
     <!ELEMENT to (#PCDATA)>
     <!ELEMENT from (#PCDATA)>
     <!ELEMENT heading (#PCDATA)>
     <!ELEMENT body (#PCDATA)>
     ]>
     <table>
     <name attr1="WEB" attr2="web2">African Coffee Table</name>
     <width>80</width>
     <length>120</length>
     </table>';
      l_parser dbe_xmlparser.parser;
      l_doc dbe_xmldom.domdocument;
     buffer varchar2(1000);
      BEGIN
      l_parser := dbe_xmlparser.newparser;
      -- Set it to false for parsing.
        dbe_xmlparser.setValidationMode(l_parser, false);
        dbe_xmlparser.parseclob(l_parser, l_clob);
        l_doc := dbe_xmlparser.getdocument(l_parser);
        dbe_xmldom.writetobuffer(l_doc, buffer);
        RAISE NOTICE '%', buffer;
        dbe_xmlparser.freeparser(l_parser);
        dbe_xmldom.freedocument(l_doc);
      END;
      /
    

    Execution result:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    NOTICE:  <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE note [
    <!ELEMENT note (to , from , heading , body)>
    <!ELEMENT to (#PCDATA)>
    <!ELEMENT from (#PCDATA)>
    <!ELEMENT heading (#PCDATA)>
    <!ELEMENT body (#PCDATA)>
    ]>
    <table>
     <name attr1="WEB" attr2="web2">African Coffee Table</name>
     <width>80</width>
     <length>120</length>
     </table>
    

    Example 2:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    -- Create a parser. The XML character string to be parsed does not match the DTD format.
    -- An error is reported during parsing after setValidationMode is set to true.
    DECLARE
      l_clob clob := 
     '<!DOCTYPE note [
     <!ELEMENT note (to,from,heading,body)>
     <!ELEMENT to (#PCDATA)>
     <!ELEMENT from (#PCDATA)>
     <!ELEMENT heading (#PCDATA)>
     <!ELEMENT body (#PCDATA)>
     ]>
     <table>
     <name attr1="WEB" attr2="web2">African Coffee Table</name>
     <width>80</width>
     <length>120</length>
     </table>';
      l_parser dbe_xmlparser.parser;
      l_doc dbe_xmldom.domdocument;
     buffer varchar2(1000);
      BEGIN
      l_parser := dbe_xmlparser.newparser;
      -- Set it to true for parsing.
    --The XML character string does not match the DTD format. An error is expected.
        dbe_xmlparser.setValidationMode(l_parser, true);
        dbe_xmlparser.parseclob(l_parser, l_clob);
        l_doc := dbe_xmlparser.getdocument(l_parser);
        dbe_xmldom.writetobuffer(l_doc, buffer);
        dbe_xmlparser.freeparser(l_parser);
        dbe_xmldom.freedocument(l_doc);
      END;
      /
    

    Execution result:

    1
    2
    An error is reported during xmlparser parsing.
    ERROR:  invalid XML document
    

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback