Skip to content

添加子元素 - XmlAppendChild

函数简介

向元素末尾添加子元素。

接口名称

XmlAppendChild

DLL调用

c
int32_t XmlAppendChild(int64_t parent, int64_t child, int32_t* err);

参数说明

参数名类型说明
parent长整数型父元素句柄。
child长整数型子元素句柄。
err整数型错误码输出参数,可为 NULL。见 XML 错误码说明

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int64_t doc = ola.XmlCreateDocument();
if (doc != 0) {
    int32_t err = 0;
    int64_t root = ola.XmlCreateElement(doc, "root", &err);
    ola.XmlInsertRootElement(doc, root, &err);
    int64_t user = ola.XmlCreateElement(doc, "user", &err);
    ola.XmlAppendChild(root, user, &err);
    ola.XmlFree(doc);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long doc = ola.XmlCreateDocument();
if (doc != 0)
{
    int err;
    long root = ola.XmlCreateElement(doc, "root", out err);
    ola.XmlInsertRootElement(doc, root, out err);
    long user = ola.XmlCreateElement(doc, "user", out err);
    ola.XmlAppendChild(root, user, out err);
    ola.XmlFree(doc);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
doc = ola.XmlCreateDocument()
if doc != 0:
    root, _ = ola.XmlCreateElement(doc, "root")
    ola.XmlInsertRootElement(doc, root)
    user, _ = ola.XmlCreateElement(doc, "user")
    ola.XmlAppendChild(root, user)
    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); }
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
doc := ola.XmlCreateDocument()
if doc != 0 {
    var err int32
    root := ola.XmlCreateElement(doc, "root", &err)
    ola.XmlInsertRootElement(doc, root, &err)
    user := ola.XmlCreateElement(doc, "user", &err)
    ola.XmlAppendChild(root, user, &err)
    ola.XmlFree(doc)
}
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let doc = ola.xml_create_document();
if doc != 0 {
    let mut err: i32 = 0;
    let root = ola.xml_create_element(doc, "root", &mut err as *mut i32);
    ola.xml_insert_root_element(doc, root, &mut err as *mut i32);
    let user = ola.xml_create_element(doc, "user", &mut err as *mut i32);
    ola.xml_append_child(root, user, &mut err as *mut i32);
    ola.xml_free(doc);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var doc = ola.XmlCreateDocument()
if(doc) { ola.XmlFree(doc) }
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
doc = ola.XmlCreateDocument()
If doc <> 0 Then ola.XmlFree(doc)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
doc = ola.XmlCreateDocument ()
.如果真 (doc ≠ 0)
    ola.XmlFree (doc)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var doc = ola.XmlCreateDocument();
if(doc){ ola.XmlFree(doc); }
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 doc = ola.XmlCreateDocument()
如果真 (doc ≠ 0) { ola.XmlFree(doc) }
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int64_t doc = ola.XmlCreateDocument();
if (doc != 0) { 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)

返回值

错误码含义见 XML 错误码说明

返回值说明
0成功。
0错误码,失败。

注意事项

项目说明
子元素会被添加到父元素的末尾子元素会被添加到父元素的末尾。
一个元素可以有多个子元素一个元素可以有多个子元素。