xml 文件解析
在用bcb 的xml data binding向导 从一个xml schema文件xx.xsd,用于生成cpp文件,解析根据xx.xsd生成的xml时,遇到当xml文件的element不在同一个namespace的时候,只解析与root element相同namespace的那些element
比如xml文件如下:
<rs:SubmitObjectsRequest
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
xmlns:rs= "urn:oasis:names:xsd:2.1 "
xmlns:rim= "urn:oasis:names:rim:xsd:2.1 "
xmlns= "urn:oasis:names:rim:xsd:2.1 "
xsi:schemaLocation= "urn:oasis:names:xsd:2.1 rs.xsd ">
<LeafRegistryObjectList>
<ObjectRef id= "urn:uuid:7edca82f-054d-47f2-a032-9b2a5b518fff "/>
<ObjectRef id= "urn:uuid:a54d6aa5-d40d-43f9-88c5-b4633d873bdd "/>
</LeafRegistryObjectList>
</rs:SubmitObjectsRequest>
SubmitObjectsRequest 与 LeafRegistryObjectList 在不同的namespace,解析时
LeafRegistryObjectList 不能正确读出,是什么原因?
[解决办法]
关注,xml data binding 没见过
xml只在.net里面处理过,bcb不会
看楼下的
[解决办法]
http://www.libing.net.cn/read.php/537.htm
[解决办法]
/**************************************.h文件**************************************/
#include <StrUtils.hpp>
#include <XMLIntf.hpp>
//---------------------------------------
class XmlFile;
class XmlDataSession;
class XmlHeader;
class XmlNode;
enum DataSessionType {dstData, dstOption};
//---------------------------------------
class XmlFile
{
private:
int current_header_count;
int current_session_index;
DynamicArray < XmlDataSession* > data_session;
AnsiString encoding;
AnsiString version;
XmlHeader *header;
public:
XmlFile();
~XmlFile();
XmlDataSession *AddDataSession(AnsiString name, DataSessionType dstype);
void Clear();
XmlDataSession *DataSession(int index){ return this-> data_session[index]; }
XmlDataSession *DataSessionByName(AnsiString name);
AnsiString Encoding(){ return this-> encoding; } // Return XML File Encoding Type
AnsiString Version(){ return this-> version; } // Returned XML File Version
XmlHeader *Header(){ return this-> header; } // Header Infomation from Returned XML File
void SetCurrentSessionIndex(int index){ this-> current_session_index = index; }
void SetDataSession(int index, XmlDataSession *session){ this-> data_session[index] = session; }
void SetDataSessionCount(int count){ this-> data_session.set_length(count); }
void SetEncoding(AnsiString encode){ this-> encoding = encode; } // Set XML File Encoding Type
void SetHeader(XmlHeader *header); // Set Header
void SetVersion(AnsiString version){ this-> version = version; } // Set XML File Version
protected:
};
class XmlHeader
{
private:
AnsiString account_date;
AnsiString code;
int data_session_count;
AnsiString date_time;
AnsiString error_uid;
AnsiString hotel_name;
AnsiString hotel_uid;
AnsiString message;
AnsiString middle_ip;
AnsiString process_time;
public:
XmlHeader();
~XmlHeader();
AnsiString AccountDate(){ return this-> account_date; }
AnsiString Code(){ return this-> code; } // Returned Code from DB
int DataSessionCount(){ return this-> data_session_count; } // Returned Data_Session from DB
AnsiString DateTime(){ return this-> date_time; } // Returned Data_Time from DB
AnsiString ErrorUid(){ return this-> error_uid; } // Returned Error_Uid from DB
AnsiString HotelName(){ return this-> hotel_name; } // Returned Hotel Name from DB
AnsiString HotelUid(){ return this-> hotel_uid; } // Returned Hotel Uid from DB
AnsiString Message(){ return this-> message; } // Returned Message from DB
AnsiString MiddleIp(){ return this-> middle_ip; } // Returned Middle Ware IP from DB
AnsiString ProcessTime(){ return this-> process_time; } // Returned Process_Time from DB
void SetAccountDate(AnsiString account_date){ this-> account_date = account_date; }
void SetCode(AnsiString code){ this-> code = code; } // Set Process_Time
void SetDataSessionCount(int count){ this-> data_session_count = count; } // Set Data_Session
void SetDateTime(AnsiString dt){ this-> date_time = dt; } // Set Date_Time
void SetErrorUid(AnsiString uid){ this-> error_uid = uid; } // Set Error Uid
void SetHotelName(AnsiString name){ this-> hotel_name = name; } // Set Hotel Name
void SetHotelUid(AnsiString uid){ this-> hotel_uid = uid; } // Set Hotel Uid
void SetMessage(AnsiString msg){ this-> message = msg; } // Set Message
void SetMiddleIp(AnsiString ip){ this-> middle_ip = ip; } // Set Middle Ware IP
void SetProcessTime(AnsiString pt){ this-> process_time = pt; } // Set Process_Time
protected:
};
class XmlDataSession
{
private:
int current_node_count;
int data_count;
DynamicArray < XmlNode* > node;
DynamicArray < DynamicArray < AnsiString > > root_node;
TStringList *roots_uid;
AnsiString session_name;
DataSessionType type;
TStringList *uid_roots;
void Parse_Node_Text(AnsiString node_text, TStringList *fields);
public:
XmlDataSession();
~XmlDataSession();
XmlNode *AddDataNode(AnsiString node_name, AnsiString node_uid);
void AddRootsUid(AnsiString uid){ roots_uid-> Add(uid); }
int DataCount(){ return this-> data_count; }
XmlNode *DataNode(int index){ return this-> node[index]; }
XmlNode *DataNodeByName(AnsiString name);
AnsiString Name(){ return this-> session_name; }
int FieldsCount(){ return this-> root_node[0].Length - 1; }
int FieldsCount(int index){ return this-> root_node[index].Length - 1; }
AnsiString FieldsName(int node_index, int field_index){ return this-> root_node[node_index][field_index]; }
int RootsCount(){ return this-> root_node.Length; }
AnsiString RootsName(int index){ return this-> root_node[index][0]; }
AnsiString RootsUid(int index){ return this-> roots_uid-> Strings[index]; }
DataSessionType Type(){ return this-> type; }
void SetAttributes(_di_IXMLNode data_node);
void SetCurrentNodeCount(int count){ current_node_count = count; }
void SetDataCount(int count);
void SetName(AnsiString session_name){ this-> session_name = session_name; }
void SetType(DataSessionType type){ this-> type = type; }
//int UidFieldsCount(int node_index){ return this-> root_uid_node[node_index].Length; }
//AnsiString UidFieldName(int node_index, int uid_field_index){ return this-> root_uid_node[node_index][uid_field_index]; }
protected:
};
class XmlNode
{
private:
TStringList *field_default;
TStringList *field_name;
TStringList *field_uid;
TStringList *field_value;
TStringList *have_uid;
AnsiString root_name;
AnsiString root_uid;
public:
XmlNode();
~XmlNode();
int FieldCount(){ return this-> field_name-> Count; }
AnsiString FieldDefault(int index){ return field_default-> Strings[index]; }
AnsiString FieldDefault(AnsiString f_name);
AnsiString FieldName(int index){ return field_name-> Strings[index]; }
AnsiString FieldUid(int index){ return field_uid-> Strings[index]; }
AnsiString FieldUid(AnsiString f_name);
AnsiString FieldValue(int index){ return field_value-> Strings[index]; }
AnsiString FieldValue(AnsiString f_name);
bool HaveUid(AnsiString f_name);
bool HaveUid(int index);
AnsiString NodeName(){ return this-> root_name; }
AnsiString NodeUid(){ return this-> root_uid; }
void SetFieldData(AnsiString f_name, AnsiString f_uid , AnsiString f_value,
AnsiString f_default, bool have_uid);
void SetNodeName(AnsiString name){ this-> root_name = name; }
void SetNodeUid(AnsiString root_uid){ this-> root_uid = root_uid; }
protected:
};
//---------------------------------------
#endif
[解决办法]
mark
[解决办法]
鹰,当时问我的时候好像说根据xml生成代码呢。原来是找读取XML的类啊?我原来Duceland Desinger自带的代码生成器支持XML parser,不过现在不支持命名空间。
回去我把Duceland Desinger升级一下以便支持命名空间,然后公布reader和writer源代码。
[解决办法]
分多就是人气旺。
传说NativeXml很不错的。
SimDesign NativeXml v2.26
http://www.ccrun.com/view.asp?id=281
[解决办法]
mark
[解决办法]
XMLDocument对有名空间的XML情况确实有点问题, 但是有些东东用XML Binding功能又很方便, 真是鲍鱼和熊掌啊:)
[解决办法]
各位大哥,我是一位刚学程序者,有好多问题,想请几位大哥帮帮我.
我想问一下:这代码有什么用啊,用来做什么呢,
谢谢各位大哥.
如有哪位大哥愿意帮我,我将万分谢谢.
给大哥我的电话:07916990403
再次谢谢.
[解决办法]
mark