CMarkup与tinyXml直接解析XML字符串
今天才知道CMarkup可以直接解析字符串形式的XML。以前都是先存入一个文件,然后从文件中load。多做了I/O操作,效率不高。
CMarkup xml;
CString str;
xml.SetDoc(str);
tinyXml也可以直接解析XML字符串,方式如下:
// directly parsing string with tinyxml
const char* content = "<root><elem name=\"aaa\"/></root>";
TiXmlDocument *doc = new TiXmlDocument();
doc->Parse(content);
if (&doc == NULL)
cout << "doc == NULL" << endl;
TiXmlHandle docHandle(doc);
TiXmlNode * root = docHandle.FirstChild("root").ToElement();
TiXmlNode * elemNode = root->FirstChild( "elem" );
TiXmlElement * elemElem = elemNode->ToElement();
cout << elemElem->Attribute("name");
结果是aaa
相关文档:
今天的项目模块中用到根据数据库里的资料生成xml文件,主要步骤如下:
(1) 连接数据库,取出数据;
(2) 创建结点,添加子项;
(3) 写入文件“test.xml”中;
具体代码如下:
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Result ......
book_schema.xml文件
<?xml version="1.0" encoding="gb2312"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="丛书">
<xs:complexType>
<xs:sequence>
<xs:element name="书">
&n ......
声明
/// <summary>
/// XML文档
/// </summary>
XmlDocument xmldoc;
&n ......
数据通常是以 XML 格式提供给 Web 应用程序的。但是,XML 数据本质上是分层的,因此您可能希望能够在基于列表的控件中使用 XML 数据,如 GridView 或 DropDownList 控件。此演练演示如何将 XML 数据视为表格数据库表中的数据进行处理。
通过此演练,您将学会如何执行以下任务:
·使用数据源控件读取 XM ......
<?
/**
* xml2array() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/
* Arguments : $contents - The XML text
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the ......