MsXml´´½¨ºÍ½âÎöXMLʾÀý
Ò»£®MsXml´´½¨XMLÎĵµÊ¾Àý
// XmlCreationDemo.cpp
#include <stdlib.h>
#include <stdio.h>
// ÒýÈëMSXML½âÎöÆ÷
#import <msxml4.dll>
using namespace MSXML2;
class InitializeCom
{
public:
InitializeCom() { CoInitialize(NULL); // Initializes the COM library }
~InitializeCom() { CoUninitialize(); // Closes the COM library }
}InitCom;
int main()
{
char *szXmlFile = "D:\\china.xml"; // xmlÎļþ
IXMLDOMDocumentPtr pDoc = NULL; // xmlÎĵµ
IXMLDOMProcessingInstructionPtr pProInstruction = NULL; // xmlÉùÃ÷
IXMLDOMCommentPtr pComment = NULL; // ×¢ÊÍ
IXMLDOMElementPtr pRootElement = NULL, pElement = NULL; // ¸ù½Úµã(ÔªËØ)
IXMLDOMNodePtr pNode = NULL, pNode1 = NULL, pNode2 = NULL; // ½Úµã
IXMLDOMAttributePtr pAttrNode = NULL; // ÊôÐÔ
HRESULT hr = pDoc.CreateInstance(__uuidof(DOMDocument40)); //
if (FAILED(hr))
{
printf("ÎÞ·¨´´½¨DOMDocument40¶ÔÏó£¬Çë¼ì²éÊÇ·ñ°²×°²¢³õʼ»¯ÁËMsXml Parser¿â£¡");
return EXIT_FAILURE;
}
// (1)´´½¨xmlÎĵµÉùÃ÷(»òinsertBefore¸ù½Úµã)
pProInstruction = pDoc->createProcessingInstruction((_bstr_t)(char*)"xml", (_bstr_t)(char*)"version=\"1.0\" encoding=\"utf-8\"");
pDoc->appendChild((IXMLDOMNode*)pProInstruction);
// (2)´´½¨¸ù½Úµã<China>
pRootElement = pDoc->createElement((_bstr_t)(char*)"China");
pDoc->PutRefdocumentElement(pRootElement); // pXMLDomDoc->documentElement = pRootElement;
// (3)´´½¨½Úµã<China><Continent>
pComment = pDoc->createComment((_bstr_t)(char*)"ËùÔÚµÄÖÞ");
pRootElement->appendChild((IXMLDOMNode*)pComment); // ×¢ÊÍ
pNode = pDoc->createNode((_variant_t)(long)NODE_ELEMENT, (_bstr_t)(char*)"Continent", (_bstr_t)(char*)"");
pNode->Puttext((_bstr_t)(char*)"Asia"); // pNode->text = "Asia";
pRootElement->appendChild(pNode); // ½Úµã
// (4)´´½¨½Úµã<China><Population>
pComment = pDoc->createComment((_bstr_t)(char*)"ÈË¿ÚÊýÁ¿");
pRootElement->appendChild((IXMLDOMNode*)pComment); // ×¢
Ïà¹ØÎĵµ£º
1£©XmlÎĵµÊ¾Àý£¨xmlsample.xml£©£º
Code
<?xml version="1.0" encoding="iso-8859-1" ?>
<music>
<song title="Oh,girl">
<artist>The Chi-lites</artist>
<genre>Soul</genre>
&nb ......
2£©ÈçºÎ´´½¨Ò»¸öxmlÎĵµ
ÓÉÓÚxmlʵÖÊÒ²Ö»ÊÇÒ»¸öÎı¾Îļþ£¬ËùÒÔ×î¼òµ¥Äã¿ÉÒÔÖ±½ÓʹÓÃSystem.IOϵÄÀàÉú³ÉÒ»¸öÎļþ£¬²¢´æ´¢³ÉxmlÎļþ£¬µ±È»£¬ÄãÐèÒªÊÖ¶¯±£Ö¤¸ÃÎļþÐÎʽÁ¼ºÃ£¬±ÈÈç±ØÐëÓиùÔªËØ¡¢±ØÐëÓйرձêÇ©¡¢±ØÐëÕýȷǶÌ׵ȵȡ£
Èç¹ûÄãÀÁµÃ×Ô¼ºÈ¥ÏëÎļþµÄÐÎʽ£¬¿ÉÒÔʹÓÃSystem.XmlϵÄÀà¡£
Code
Xml ......
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
SAXReader reader = new SAXReader();
try {
Document doc = reader.read("ParserSQL.xml");
&n ......
ÒýÑÔ
Èç¹ûÄãÒѾ¿´ÁËAsp.Net AjaxµÄÁ½ÖÖ»ù±¾¿ª·¢Ä£Ê½ ÕâÆªÎÄÕ£¬Äã¿ÉÄܺܿì»á·¢ÏÖÕâÑùÒ»¸öÎÊÌ⣺ÔÚÄÇÆªÎÄÕµķ½Ê½2ÖУ¬¿Í»§¶Ë½ö½öÊÇ·¢ËÍÁËÒ³ÃæÉÏÒ»¸öÎı¾¿òµÄÄÚÈݵ½·þÎñ¶Ë£¬¶ø·þÎñ¶ËµÄWeb·þÎñ·½·¨Ò²Ö»½ÓÊÕÒ»¸öÀ´×Ô¿Í»§¶ËµÄ×Ö·û´®ÀàÐ͵ÄÊýÖµ¡£¶øºÜ¶àʱºò£¬·þÎñ¶ËµÄ·½·¨ÆÚÍû½ÓÊÕµÄÊÇÒ»¸ö×Ô¶¨ÒåÀàÐÍ£¬»òÕßÊǶà¸ö²»Í¬ÀàÐ͵IJÎÊ ......
JAVA¶ÁXML£ºsax,dom,jdom,dom4jµÄ±È½ÏÒÔ¼°Ñ¡Ôñ(ת)
ÔÎÄ£ºwww.hicourt.gov.cn/homepage/show9_content.asp
SAX£º ......