Êý¾Ýͨ³£ÊÇÒÔ XML ¸ñʽÌṩ¸ø Web Ó¦ÓóÌÐòµÄ¡£µ«ÊÇ£¬XML Êý¾Ý±¾ÖÊÉÏÊÇ·Ö²ãµÄ£¬Òò´ËÄú¿ÉÄÜÏ£ÍûÄܹ»ÔÚ»ùÓÚÁбíµÄ¿Ø¼þÖÐʹÓà XML Êý¾Ý£¬Èç GridView »ò DropDownList ¿Ø¼þ¡£´ËÑÝÁ·ÑÝʾÈçºÎ½« XML Êý¾ÝÊÓΪ±í¸ñÊý¾Ý¿â±íÖеÄÊý¾Ý½øÐд¦Àí¡£
ͨ¹ý´ËÑÝÁ·£¬Äú½«Ñ§»áÈçºÎÖ´ÐÐÒÔÏÂÈÎÎñ£º
·Ê¹ÓÃÊý¾ÝÔ´¿Ø¼þ¶ÁÈ¡ XML Êý¾Ý²¢½«Êý¾ÝÌṩ¸øÁбí¿Ø¼þ¡£
·½« GridView ºÍ DataList ¿Ø¼þ°ó¶¨µ½ XML Êý¾Ý¡£
·´´½¨ÏÔʾÂß¼Ïà¹ØµÄ XML Êý¾ÝµÄÖ÷ÏêϸÐÅÏ¢Ò³¡£
·¶Ô .xml ÎļþÓ¦ÓÃת»»ÒÔʹ¸ÃÎļþ¿ÉÓÃ×÷±í¸ñÊý¾Ý¡£
Ò»¡¢´´½¨ÍøÕ¾
Èç¹ûÒѾÔÚ Visual Web Developer Öд´½¨ÁËÒ»¸öÍøÕ¾£¨ÀýÈ磬°´ÕÕ ÑÝÁ·£ºÔÚ Visual Web Developer Öд´½¨»ù±¾ÍøÒ³ ÖеIJ½Ö裩£¬Ôò¿ÉÒÔʹÓøÃÍøÕ¾²¢×ªµ½ÏÂÒ»²¿·Ö¡£·ñÔò£¬°´ÕÕÏÂÃæµÄ²½Öè´´½¨Ò»¸öеÄÍøÕ¾ºÍÍøÒ³¡£´´½¨ÎļþϵͳÍøÕ¾£º
1¡¢´ò¿ª Visual Web Developer¡£
2¡¢ÔÚ“Îļþ”²Ëµ¥ÉÏÖ¸Ïò“н¨ÍøÕ¾”¡£³öÏ֓н¨ÍøÕ¾”¶Ô»°¿ò¡£
3¡¢ÔÚ“Visual Studio ÒÑ°²×°µÄÄ£°å”֮ϵ¥»÷“ASP.NET ÍøÕ¾”¡£
4ÔړλÖÔ¿òÖе¥»÷“Îļþϵͳ”£¬È»ºóÊ ......
Êý¾Ýͨ³£ÊÇÒÔ XML ¸ñʽÌṩ¸ø Web Ó¦ÓóÌÐòµÄ¡£µ«ÊÇ£¬XML Êý¾Ý±¾ÖÊÉÏÊÇ·Ö²ãµÄ£¬Òò´ËÄú¿ÉÄÜÏ£ÍûÄܹ»ÔÚ»ùÓÚÁбíµÄ¿Ø¼þÖÐʹÓà XML Êý¾Ý£¬Èç GridView »ò DropDownList ¿Ø¼þ¡£´ËÑÝÁ·ÑÝʾÈçºÎ½« XML Êý¾ÝÊÓΪ±í¸ñÊý¾Ý¿â±íÖеÄÊý¾Ý½øÐд¦Àí¡£
ͨ¹ý´ËÑÝÁ·£¬Äú½«Ñ§»áÈçºÎÖ´ÐÐÒÔÏÂÈÎÎñ£º
·Ê¹ÓÃÊý¾ÝÔ´¿Ø¼þ¶ÁÈ¡ XML Êý¾Ý²¢½«Êý¾ÝÌṩ¸øÁбí¿Ø¼þ¡£
·½« GridView ºÍ DataList ¿Ø¼þ°ó¶¨µ½ XML Êý¾Ý¡£
·´´½¨ÏÔʾÂß¼Ïà¹ØµÄ XML Êý¾ÝµÄÖ÷ÏêϸÐÅÏ¢Ò³¡£
·¶Ô .xml ÎļþÓ¦ÓÃת»»ÒÔʹ¸ÃÎļþ¿ÉÓÃ×÷±í¸ñÊý¾Ý¡£
Ò»¡¢´´½¨ÍøÕ¾
Èç¹ûÒѾÔÚ Visual Web Developer Öд´½¨ÁËÒ»¸öÍøÕ¾£¨ÀýÈ磬°´ÕÕ ÑÝÁ·£ºÔÚ Visual Web Developer Öд´½¨»ù±¾ÍøÒ³ ÖеIJ½Ö裩£¬Ôò¿ÉÒÔʹÓøÃÍøÕ¾²¢×ªµ½ÏÂÒ»²¿·Ö¡£·ñÔò£¬°´ÕÕÏÂÃæµÄ²½Öè´´½¨Ò»¸öеÄÍøÕ¾ºÍÍøÒ³¡£´´½¨ÎļþϵͳÍøÕ¾£º
1¡¢´ò¿ª Visual Web Developer¡£
2¡¢ÔÚ“Îļþ”²Ëµ¥ÉÏÖ¸Ïò“н¨ÍøÕ¾”¡£³öÏ֓н¨ÍøÕ¾”¶Ô»°¿ò¡£
3¡¢ÔÚ“Visual Studio ÒÑ°²×°µÄÄ£°å”֮ϵ¥»÷“ASP.NET ÍøÕ¾”¡£
4ÔړλÖÔ¿òÖе¥»÷“Îļþϵͳ”£¬È»ºóÊ ......
<?
/**
* 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 tag values - this results in a different array structure in the return value.
* $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
* Return: The parsed XML in an array form. Use print_r() to see the resulting array structure.
* Examples: $array = xml2array(file_get_contents('feed.xml'));
* $array = xml2array(file_get_contents('feed.xml', 1, 'attribute'));
*/
function xml2array($contents, $get_attributes=1, $priority = 'tag') {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' ......
<?
/**
* 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 tag values - this results in a different array structure in the return value.
* $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
* Return: The parsed XML in an array form. Use print_r() to see the resulting array structure.
* Examples: $array = xml2array(file_get_contents('feed.xml'));
* $array = xml2array(file_get_contents('feed.xml', 1, 'attribute'));
*/
function xml2array($contents, $get_attributes=1, $priority = 'tag') {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' ......
ͬ²½³ÌÐò°¸Àý
procedure TGetOrderThread.PostDB(webnr:WideString);
var
Err: String;
SetWebnr:WideString;
xmlDoc: IXMLDocument;
root: IXMLNode;
rowc: IXMLNode;//¼Ç¼Êý
rows: IXMLNodeList;//Ö÷¼Ç¼Áбí
row: IXMLNode;
drows: IXMLNodeList;//Ã÷ϸÁбí
drow: IXMLNode;
i,j,slhj,jlhj:integer;
djhj:real;
begin
//ͬ²½Êý¾Ý
xmlDoc := TXMLDocument.Create(nil);
try
xmlDoc.XML.Text:=Webnr;
xmlDoc.Active:=true;
root:=xmlDoc.DocumentElement;
rowc:=root.ChildNodes.FindNode('RowC');
if (rowc.NodeValue>0) and DBconn then
begin
rows:=root.ChildNodes.FindNode('RowS').ChildNodes;
//showmessage('¼Ç¼Êý:'+rowc.NodeValue);
for i:=0 to rows.Count-1 do
begin ......
ͬ²½³ÌÐò°¸Àý
procedure TGetOrderThread.PostDB(webnr:WideString);
var
Err: String;
SetWebnr:WideString;
xmlDoc: IXMLDocument;
root: IXMLNode;
rowc: IXMLNode;//¼Ç¼Êý
rows: IXMLNodeList;//Ö÷¼Ç¼Áбí
row: IXMLNode;
drows: IXMLNodeList;//Ã÷ϸÁбí
drow: IXMLNode;
i,j,slhj,jlhj:integer;
djhj:real;
begin
//ͬ²½Êý¾Ý
xmlDoc := TXMLDocument.Create(nil);
try
xmlDoc.XML.Text:=Webnr;
xmlDoc.Active:=true;
root:=xmlDoc.DocumentElement;
rowc:=root.ChildNodes.FindNode('RowC');
if (rowc.NodeValue>0) and DBconn then
begin
rows:=root.ChildNodes.FindNode('RowS').ChildNodes;
//showmessage('¼Ç¼Êý:'+rowc.NodeValue);
for i:=0 to rows.Count-1 do
begin ......
ArrayCollectionת³ÉxmlÀàÐÍʾÀý
ÏÂÃæÄ£ÄâÒ»×éÊý¾Ýexams,½«Æäת»¯ÎªxmlÐÎʽ.Ïêϸ´úÂë¼ûÏ£º
Xml´úÂë
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="init()">
<mx:Style source="style/Smoke.css"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var shijxml:XML;
private function init():void{
& ......
ArrayCollectionת³ÉxmlÀàÐÍʾÀý
ÏÂÃæÄ£ÄâÒ»×éÊý¾Ýexams,½«Æäת»¯ÎªxmlÐÎʽ.Ïêϸ´úÂë¼ûÏ£º
Xml´úÂë
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="init()">
<mx:Style source="style/Smoke.css"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var shijxml:XML;
private function init():void{
& ......
½ñÌì²ÅÖªµÀ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(); & ......
ÏÂÎç¿´ÁËÒ»ÏÂdomºÍdom4j£¬¸Ð¾õÕâÁ½ÕßÔÚ½âÎö·½Ãæ²î²»¶à£¬µ«ÊÇdom4jÒª±Èdom¼òµ¥Ò»Ð©£¬ÔÚ´´½¨Ò»¸öxmlÎļþ£¬dom4jÒª±Èdom¼òµ¥Ì«¶àÁË£¬±Ï¾¹È˼Ҷ¼°ïÎÒÃÇ·â×°ºÃÁË¡£
domÊDz»ÐèÒª¼Ó°üµÄ£¬¶ødom4jÒª¼ÓÒ»¸ödom4j-1.6.1.jarÕâ¸ö°ü¡£¾ßÌåµÄÏÂÔØ·¾¶ÊÇ£ºhttp://www.dom4j.org/
ÏÂÃæÎÒ˵һÏÂÕâÁ½ÕßÈçºÎ½âÎöºÍ´´½¨£¬ÒÔ¼°ËûÃǵÄÇø±ð¡£xml¸öÈ˾õµÃÊÇÂùÖØÒªµÄ£¬ÒòΪËüÊÇ¿ÉÀ©Õ¹µÄ£¬Ôõô˵ÄØ£¬xmlÒ²Ðí»á´úÌæhtml¡£
domµÄ½âÎöµÄ´úÂëÈçÏ£º
private static void read() {
File file = new File("src/xml/student.xml");
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(file);
NodeList node = doc.getChildNodes();
for (int i = 0; i < node.getLength(); i++) {
Element e = (Element) node.item(i);
// System.out.println(e.getNodeName());
boolean flag = e.hasChildNodes();
if (flag) {
NodeList list = e.getChildNodes();
for (int j = 0; j < list.getLength(); j++) {
e ......