主题
释放XML文档 - XmlFree
函数简介
释放XML文档对象及其占用的所有资源。
接口名称
XmlFreeDLL调用
c
int32_t XmlFree(int64_t doc);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| doc | 长整数型 | 要释放的XML文档句柄。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 假设 xmlStr 来自 HTTP 响应、配置文件或文件读取
const char* xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
int32_t err = 0;
int64_t doc = ola.XmlParse(xmlStr, &err);
if (doc != 0 && err == 0) {
int32_t rootErr = 0;
ola.XmlGetRootElement(doc, &rootErr);
ola.XmlFree(doc); // 必须释放,否则内存泄漏
ola.XmlFree(doc);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
// 假设 xmlStr 来自 HTTP 响应、配置文件或文件读取
string xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
int err;
long doc = ola.XmlParse(xmlStr, out err);
if (doc != 0 && err == 0)
{
int rootErr;
ola.XmlGetRootElement(doc, out rootErr);
ola.XmlFree(doc); // 必须释放,否则内存泄漏
ola.XmlFree(doc);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 假设 xml_str 来自 HTTP 响应、配置文件或文件读取
xml_str = '<root><user id="1" enabled="true" level="10"><name>ola</name><role>admin</role></user></root>'
doc, err = ola.XmlParse(xml_str)
if doc != 0 and err == 0:
ola.XmlGetRootElement(doc)
ola.XmlFree(doc) # 必须释放,否则内存泄漏
ola.XmlFree(doc)java
import com.olaplug.OLAPlugServer;
import com.sun.jna.ptr.IntByReference;
OLAPlugServer ola = new OLAPlugServer();
// 假设 xmlStr 来自 HTTP 响应、配置文件或文件读取
String xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
IntByReference err = new IntByReference(0);
long doc = com.olaplug.OLAPlugDLLHelper.XmlParse(xmlStr, err);
if (doc != 0 && err.getValue() == 0) {
ola.XmlFree(doc);
ola.XmlFree(doc);
}cpp
var ola = com("OlaPlug.OlaSoft")
// 假设 xmlStr 来自配置文件等
var xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>"
var err = 0
var doc = ola.XmlParse(xmlStr, err)
if(doc && err == 0) {
ola.XmlGetRootElement(doc, 0)
ola.XmlFree(doc)
ola.XmlFree(doc)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 假设 xmlStr 来自配置文件等
xmlStr = "<root><user id=""1"" enabled=""true"" level=""10""><name>ola</name><role>admin</role></user></root>"
err = 0
doc = ola.XmlParse(xmlStr, err)
If doc <> 0 And err = 0 Then
ola.XmlFree(doc) ' 必须释放
ola.XmlFree(doc)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
' 假设 xmlStr 来自配置文件等
xmlStr = “<root><user id=“1“ enabled=“true“ level=“10“><name>ola</name><role>admin</role></user></root>“
err = 0
doc = ola.XmlParse (xmlStr, err)
.如果真 (doc ≠ 0 且 err = 0)
ola.XmlFree (doc) ' 必须释放
ola.XmlFree (doc)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 假设 xmlStr 来自配置文件等
var xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
var err = 0;
var doc = ola.XmlParse(xmlStr, err);
if(doc && !err){
ola.XmlFree(doc); // 必须释放
ola.XmlFree(doc);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 假设 xmlStr 来自配置文件等
文本型 xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>"
整数 err = 0
长整数 doc = ola.XmlParse(xmlStr, err)
如果真 (doc ≠ 0 且 err = 0)
{
ola.XmlFree(doc) // 必须释放
ola.XmlFree(doc)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 假设 xmlStr 来自 HTTP 响应、配置文件或文件读取
const char* xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
int32_t err = 0;
int64_t doc = ola.XmlParse(xmlStr, &err);
if (doc != 0 && err == 0) {
ola.XmlFree(doc); // 必须释放
ola.XmlFree(doc);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
const char* xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
int err = 0;
long doc = XmlParse(instance, xmlStr, &err);
if (doc != 0 && err == 0) {
XmlFree(instance, doc);
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();
string xmlStr = "<root><user id=\"1\" enabled=\"true\" level=\"10\"><name>ola</name><role>admin</role></user></root>";
int err = 0;
long doc = XmlParse(instance, xmlStr, err);
if (doc != 0 && err == 0)
{
XmlFree(instance, doc);
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()
xml_str = b'<root><user id="1" enabled="true" level="10"><name>ola</name><role>admin</role></user></root>'
err = c_int(0)
doc = ola.XmlParse(instance, xml_str, err)
if doc and err.value == 0:
XmlFree(instance, doc);
ola.XmlFree(instance, doc)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 释放文档后 | 释放文档后,所有相关的元素句柄都会失效。 |
| 必须在程序结束前释放所有创建的XML文档 | 必须在程序结束前释放所有创建的XML文档。 |
| 重复释放同一个文档会导致错误 | 重复释放同一个文档会导致错误。 |
| 释放文档会自动释放其包含的所有元素和属性 | 释放文档会自动释放其包含的所有元素和属性。 |
