2025-01-07 12:51:19 +08:00
|
|
|
|
#pragma once
|
2024-12-25 00:28:54 +08:00
|
|
|
|
|
2025-01-07 12:51:19 +08:00
|
|
|
|
#include<hgl/type/Map.h>
|
2025-01-04 14:16:03 +08:00
|
|
|
|
#include<hgl/type/String.h>
|
2024-12-25 00:28:54 +08:00
|
|
|
|
#include<hgl/type/StringView.h>
|
2025-01-07 12:51:19 +08:00
|
|
|
|
#include<hgl/type/Pair.h>
|
2025-01-04 14:16:03 +08:00
|
|
|
|
|
2024-12-25 00:28:54 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace xml
|
|
|
|
|
{
|
|
|
|
|
//TreeXML可以直接将整个XML解晰到一个树形结构中
|
|
|
|
|
//对于访问解晰非常的友好
|
|
|
|
|
|
|
|
|
|
//但由于要一次性保存整个树形结构,所以对内存消耗较大,且必须等到整个XML解晰完才可以访问。
|
|
|
|
|
//所以TreeXML仅限于对小型XML文件的解晰,对于大型XML文件,还是使用XMLParse进行流式解晰比较好。
|
|
|
|
|
|
2025-01-04 14:16:03 +08:00
|
|
|
|
struct TreeXMLData
|
2024-12-25 00:28:54 +08:00
|
|
|
|
{
|
|
|
|
|
using XSVList=List<U8StringView>;
|
|
|
|
|
|
2025-01-04 14:16:03 +08:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
U8StringView xml_raw_data; ///<XML原始数据
|
2024-12-25 00:28:54 +08:00
|
|
|
|
|
|
|
|
|
XSVList ElementNameList; ///<所有元素点名字文本视图
|
|
|
|
|
XSVList AttsList; ///<所有属性点名字文本视图
|
|
|
|
|
XSVList InfoList; ///<所有属性点信息文本视图
|
|
|
|
|
XSVList DataList; ///<数据文本视图
|
2025-01-04 14:16:03 +08:00
|
|
|
|
};
|
2024-12-25 00:28:54 +08:00
|
|
|
|
|
2025-01-04 14:16:03 +08:00
|
|
|
|
class TreeXMLNode
|
|
|
|
|
{
|
|
|
|
|
/**
|
2025-01-07 12:51:19 +08:00
|
|
|
|
<node number="123456">
|
2025-01-04 14:16:03 +08:00
|
|
|
|
abcdefg
|
|
|
|
|
</root>
|
2024-12-25 00:28:54 +08:00
|
|
|
|
|
2025-01-07 12:51:19 +08:00
|
|
|
|
name root
|
|
|
|
|
atts number=123456
|
|
|
|
|
data abcdefg
|
2025-01-04 14:16:03 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
TreeXMLData * xml_raw_data;
|
|
|
|
|
|
2025-01-07 12:51:19 +08:00
|
|
|
|
int name; ///<元素点名字视图
|
|
|
|
|
Map<int,int> atts; ///<属性点文字视图
|
|
|
|
|
int data; ///<数据文本视图
|
2025-01-04 14:16:03 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
TreeXMLNode(TreeXMLData *,int);
|
|
|
|
|
|
|
|
|
|
void AddAtts(int,int);
|
|
|
|
|
void SetData(int);
|
2024-12-25 00:28:54 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2025-01-04 14:16:03 +08:00
|
|
|
|
const U8StringView *GetElementName()const;
|
|
|
|
|
|
|
|
|
|
const U8StringView *GetAtts(const U8String &);
|
|
|
|
|
const U8StringView *GetAtts(const U8StringView &);
|
|
|
|
|
|
|
|
|
|
const U8StringView *GetData()const;
|
|
|
|
|
};
|
2024-12-25 00:28:54 +08:00
|
|
|
|
|
2025-01-04 14:16:03 +08:00
|
|
|
|
TreeXMLNode *ParseXMLToTree(U8StringView);
|
2024-12-25 00:28:54 +08:00
|
|
|
|
}//namespace xml
|
|
|
|
|
}//namespace hgl
|