XML over TCP
Èç¹ûÒªÍêÕûµÄÖ§³ÖXML over TCP£¬Ö»ÓÐÁ½ÖÖ°ì·¨£º
1£¬¼ÓÒ»¸öheaderÈ¥±êÃ÷Êý¾ÝµÄ³¤¶È
2£¬¼ÓÒ»¸ödelimiterÈ¥±êÃ÷Êý¾ÝµÄ½áÊø
ÕâÁ½ÖÖ·½·¨¶¼²»¹»ÓÅÑÅ¡£ÎÒÃDz»ÐèÒªÒ»¸öͨÓõķ½·¨£¬ÎÒÃÇÖ»ÒªÒ»¸ö×îÊʺÏÎÒÃǵķ½·¨¡£
ͨ³££¬ÎÒÃÇÄܹ»×Ô¶¨ÒåÊý¾ÝµÄ¸ñʽ£¬¶øÇÒÎÒÃÇͨ³£Ò»ÌõÏûÏ¢Ö»ÓÐÒ»¸öroot node£¬ÄÇôÎÒÃÇ¿ÉÒÔÊÔÊÔÏÂÃæµÄº¯Êý£º
//return length of the xml message
//return -1 for invalid data
//return 0 for not fully received
int GetXmlLen(string buf, string rootName)
{
string head = "<" + rootName;
if (buf.Length < head.Length)
{
//not fully recved
return 0;
}
if (!buf.StartsWith(head))
{
//invalid
return -1;
}
int idx = buf.IndexOf('>');
if (idx < 0)
{
//not fully recved
return 0;
}
if (buf[idx-1] == '/')
{
//empty root element
return (idx + 1);
}
string tail = "</" + rootName + ">";
idx = buf.IndexOf(tail);
if (idx < 0)
{
//not fully recved
return 0;
}
return (idx + tail.Length);
}
ÒªÇó£ºXMLÏûÏ¢Ö»ÓÐÒ»¸öroot node£¬rootName²»ÊÇÈκÎ×Ó½ÚµãµÄÃû×Ö£¬¶øÇÒÏûÏ¢ÊÇÒÔ"/>"»òÕß"</rootName>"½áβ¡£
Õâ²¢²»ÊǺܿÁ¿ÌµÄÒªÇ󣬴ó¶àÊý»ùÓÚXMLµÄÐÒéʵ¼ÊÉϾÍÊÇÕâÑùµÄ¡£
Èç¹ûÄãµÄXMLÐÒéÂú×ãÉÏÊöÒªÇó£¬ÄÇôµ±ÄãÔÚTCPÉÏ´«ÊäXMLµÄʱºò£¬¾Í¿ÉÒÔÊÔÊÔÎҵĺ¯Êý¡£
PS£ºÕâ¸öʾÀýº¯ÊýÊÇÓÃC#дµÄ£¬ÓÃÆäËûÓïÑÔÒ²ºÜÈÝÒ×ʵÏÖͬÑùµÄ¹¦ÄÜ¡£
Ïà¹ØÎĵµ£º
ÏÂÔØ dom4j-1.6.1.jar¡£
1: package org.zzp.common.xml.dom4j;
2:
3: import java.io.FileWriter;
4: import java.io.IOException;
5: import org.dom4j.Document;
6: import org.dom4j.DocumentHelper;
7: import org.dom4j.Element;
8: import org.dom4j.io.OutputFormat;
9: impor ......
Introduction to XML and XML With Java
If you are looking for sample programs to parse a XML file using DOM/SAX parser or looking for a program to generate a XML file please proceed directly to programs.
This small tutorial introduces you to the basic concepts of XML and using Xer ......
ÔںܶàÇé¿öÏÂ, ÎÒÃÇ»áÓõ½XML,±ÈÈç˵ÅäÖÃÎļþµÈ.C#ÌṩÁËXMLÀà.
ÕâÀïÎÒÖ»ÊǼòµ¥µÄдһÏÂXMLÎļþµÄÉú³É,½âÎö¾Í²»¶à˵ÁË.
µÚÒ»ÖÖ·½·¨
DataBase db = DataBaseFactory.CreateDataBase(DataBaseType.MySql, strMysql);
......
Ò»£ºSpringÖеļ¸ÖÖÈÝÆ÷¶¼Ö§³ÖʹÓÃxml×°Åäbean£¬°üÀ¨£º
XmlBeanFactory £¬
ClassPathXmlApplicationContext £¬
FileSystemXmlApplicationContext £¬
XmlWebApplicationContext
¼ÓÔØÕâЩÈÝÆ÷µÄÅäÖÃÎļþµÄxmlÓÐһϼ¸ÖÖ³£¼ûµ ......
µ±ÔÚPerlÖÐʹÓÃXMLʱ£¬Äã»áÓн«½üÎå°Ù¸öCPANÄ£¿é¿ÉÒÔÑ¡Ôñ£¬Ã¿Ò»¸ö¶¼Ö§³ÖÕûºÏWeb·þÎñµÄ²»Í¬·½Ãæ¡£´ËÍ⣬PerlµÄºËÐÄ¿â°üÀ¨¶à¸öÖ§³ÖXMLµÄÄ£¿é¡£ÕâÆªÎÄÕ¾͹Ø×¢ÓÚÒ»¸ö×îÔçÆÚÇÒÉæ¼°×îÆµ·±µÄºËÐÄÄ£¿é£ºXML::Parser.
XML::½âÎöÆ÷ϵÁÐ
×î³õµÄPerl½âÎöÆ÷XML::Parser::ExpatÓÉLarry WallÔÚ¼¸Äêǰ±àд²¢ÓÉClark Cooper±£³ÖÑÓÐø¡£Ä£ ......