Skip to content

创建空XML文档 - XmlCreateDocument

函数简介

创建一个新的空XML文档对象。

接口名称

XmlCreateDocument

DLL调用

c
int64_t XmlCreateDocument();

参数说明

参数名类型说明
--。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int64_t doc = ola.XmlCreateDocument();
if (doc != 0) {
    int32_t elemErr = 0;
    int64_t root = ola.XmlCreateElement(doc, "root", &elemErr);
    int32_t insErr = 0;
    ola.XmlInsertRootElement(doc, root, &insErr);
    int32_t strErr = 0;
    std::string xmlOut = ola.XmlToString(doc, 0, &strErr);
    ola.XmlFree(doc);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long doc = ola.XmlCreateDocument();
if (doc != 0)
{
    int elemErr, insErr, strErr;
    long root = ola.XmlCreateElement(doc, "root", out elemErr);
    ola.XmlInsertRootElement(doc, root, out insErr);
    string xmlOut = ola.XmlToString(doc, 0, out strErr);
    ola.XmlFree(doc);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
doc = ola.XmlCreateDocument()
if doc != 0:
    root, elem_err = ola.XmlCreateElement(doc, "root")
    ola.XmlInsertRootElement(doc, root)
    xml_out, str_err = ola.XmlToString(doc, 0)
    ola.XmlFree(doc)
java
import com.olaplug.OLAPlugServer;
import com.sun.jna.ptr.IntByReference;

OLAPlugServer ola = new OLAPlugServer();
long doc = ola.XmlCreateDocument();
if (doc != 0) {
    ola.XmlFree(doc);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var doc = ola.XmlCreateDocument()
if(doc) {
    var root = ola.XmlCreateElement(doc, "root", 0)
    ola.XmlInsertRootElement(doc, root, 0)
    ola.XmlFree(doc)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
doc = ola.XmlCreateDocument()
If doc <> 0 Then
    root = ola.XmlCreateElement(doc, "root", 0)
    ola.XmlInsertRootElement(doc, root, 0)
    ola.XmlFree(doc)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
doc = ola.XmlCreateDocument ()
.如果真 (doc ≠ 0)
    root = ola.XmlCreateElement (doc, "root", 0)
    ola.XmlInsertRootElement (doc, root, 0)
    ola.XmlFree (doc)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var doc = ola.XmlCreateDocument();
if(doc){
    var root = ola.XmlCreateElement(doc, "root", 0);
    ola.XmlInsertRootElement(doc, root, 0);
    ola.XmlFree(doc);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 doc = ola.XmlCreateDocument()
如果真 (doc ≠ 0)
{
    长整数 root = ola.XmlCreateElement(doc, "root", 0)
    ola.XmlInsertRootElement(doc, root, 0)
    ola.XmlFree(doc)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int64_t doc = ola.XmlCreateDocument();
if (doc != 0) {
    int32_t elemErr = 0;
    int64_t root = ola.XmlCreateElement(doc, "root", &elemErr);
    ola.XmlInsertRootElement(doc, root, &elemErr);
    ola.XmlFree(doc);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long doc = XmlCreateDocument(instance);
if (doc != 0) {
    int err = 0;
    long root = XmlCreateElement(instance, doc, "root", &err);
    XmlInsertRootElement(instance, doc, root, &err);
    XmlFree(instance, doc);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long doc = XmlCreateDocument(instance);
if (doc != 0) {
    int err = 0;
    long root = XmlCreateElement(instance, doc, "root", err);
    XmlInsertRootElement(instance, doc, root, err);
    XmlFree(instance, doc);
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
doc = ola.XmlCreateDocument(instance)
if doc:
    err = c_int(0)
    root = ola.XmlCreateElement(instance, doc, b"root", err)
    ola.XmlInsertRootElement(instance, doc, root, err)
    ola.XmlFree(instance, doc)

返回值

返回值说明
非 0返回 新创建的XML文档句柄。
0失败。

注意事项

项目说明
创建的文档需要调用 XmlFree 释放资源创建的文档需要调用 XmlFree 释放资源。
新创建的文档是空的新创建的文档是空的,需要手动添加根元素。
建议使用 XmlSetDeclaration建议使用 XmlSetDeclaration 设置XML声明。