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); // ×¢
Ïà¹ØÎĵµ£º
2£©ÈçºÎ´´½¨Ò»¸öxmlÎĵµ
ÓÉÓÚxmlʵÖÊÒ²Ö»ÊÇÒ»¸öÎı¾Îļþ£¬ËùÒÔ×î¼òµ¥Äã¿ÉÒÔÖ±½ÓʹÓÃSystem.IOϵÄÀàÉú³ÉÒ»¸öÎļþ£¬²¢´æ´¢³ÉxmlÎļþ£¬µ±È»£¬ÄãÐèÒªÊÖ¶¯±£Ö¤¸ÃÎļþÐÎʽÁ¼ºÃ£¬±ÈÈç±ØÐëÓиùÔªËØ¡¢±ØÐëÓйرձêÇ©¡¢±ØÐëÕýȷǶÌ׵ȵȡ£
Èç¹ûÄãÀÁµÃ×Ô¼ºÈ¥ÏëÎļþµÄÐÎʽ£¬¿ÉÒÔʹÓÃSystem.XmlϵÄÀà¡£
Code
Xml ......
¡¡¡¡inkfishÔ´´£¬ÇëÎðÉÌÒµÐÔÖÊתÔØ£¬×ªÔØÇë×¢Ã÷À´Ô´£¨http://blog.csdn.net/inkfish
£©¡£
¡¡¡¡PropertySet£¨À´Ô´£ºhttp://blog.csdn.net/inkfish£©
ÊÇÓÉopensymphony×éÖ¯¿ª·¢µÄµÄÒ»¸ö¿ªÔ´ÏîÄ¿£¬µ«ÊÇÄǸöÏîÄ¿ÎĵµÉÙ£¬³¤Ê±¼äûÓиüУ¬¹Ù·½Îĵµ´íÎóÆæ¶à£¬ËùÒÔÏÖÔÚÔÚÏîÄ¿ÖÐʹÓò¢²»¹ã·º¡£µ«Õâ²¢²»·Á°PropertySet³ÉΪһ¸öÓ ......
LSParserFilter---ÔØÈëÓë±£´æ
Ó¦ÓÃorg.w3c.dom ʵÏÖXMLµÄÔØÈëÓë±£´æʵÀý
/**
* ʵÏÖDOM3µÄLS(Load & Save)¹¦ÄÜ
*
* @author S.Well
* @see org.w3c.dom.DOMErrorHandler
* @see org.w3c.dom.ls.LSParserFilter
*/
public class XML_LS implements DOMErrorHandler, LSParserFilter {
private static ......
JAVA¶ÁXML£ºsax,dom,jdom,dom4jµÄ±È½ÏÒÔ¼°Ñ¡Ôñ(ת)
ÔÎÄ£ºwww.hicourt.gov.cn/homepage/show9_content.asp
SAX£º ......