主题
创建元素 - XmlCreateElement
函数简介
创建新的XML元素。
接口名称
XmlCreateElementDLL调用
c
int64_t XmlCreateElement(int64_t doc, const char* name, int32_t* err);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| doc | 长整数型 | XML文档句柄。 |
| name | 字符串 | 元素名称。 |
| err | 整数型 | 错误码输出参数,可为NULL。 |
示例
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 Iftext
.局部变量 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 | 返回 元素句柄。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 创建的元素需要添加到文档树中才能生效 | 创建的元素需要添加到文档树中才能生效。 |
| 元素名称不能为空 | 元素名称不能为空。 |
| 元素句柄在文档释放后失效 | 元素句柄在文档释放后失效。 |
