Using XML Aweay in C ++ Builder6 [original]

xiaoxiao2021-03-06  160

Recently, someone often saw someone inquiry how to use XML in C Builer, starting the author also thinking is inexplicable, first XML technology seems to be linked to the network, or SOAP / Web Service, second C Builer provides TXMLDocument components, it should be very user-friendly. These days were studying Tomcat, found that its profile was written in XML files, and it seems that this represents the software's advanced type :), so I also decided to use C Builer to operate XML files to increase their own software. At this time, I deeply feel the confusion of those inquiors, and the TXmldocument component is really difficult. If there is an experience of the ASP XML construction website, I really have to be difficult to fall by this problem :), nonsense, talk to the topic . Processing XML files must of course require XML Parser, and XML Parse includes SAX, DOM, and SAX is relatively simple. The DOM model is more difficult, and C Builer is using the DOM model to process XML files, so mainly discussed here DOM model processing method. The TXMLDocument component uses the MS XML DOM model to process XML, MSXmldom is COM based, using this COM in tools such as VB, and it is not easy in C Builer, I think it is large because We are very easy to understand and use, and many methods are very easy to understand. Many methods are meaningless, and even help do not need to be checked, and the author has to check when using TXMLDocument, many methods can not be accurate Know what it means, and even traps. Below I told everyone how to use TXMLDocument to process XML. This example is that, the author needs a minor program for a timed reminder schedule, assuming that other functions are completed, how is the problem now? Save our schedule, here in order to use XML, it is of course stored in XML file format. For a schedule, it is definitely necessary to add a deleted function, and the substantially above operation already contains all of the processing XML. Let's design XML file (TIP.XML): // Note The encoding format here is GB2312, otherwise there is garbled 0

The first is to open XML, the current code snippet shows this process: xmldoc-> loadFromfile (WideString (AppPath) "Tip.xml"))); // Xmldoc is the name of TXmldocument xmlDoc-> Active = true; FillList (); // Add XML content to listView then how to read XML content (FillList): LSTMAIN-> items-> beginupdate (); lstimain-> items-> clear (); _di_ixmlnode node = xmldoc > DocumentElement; // DocumentElement property is used to get root node _di_ixmlnodelist nodes = node-> childnodes; // Get child node list for (int N = 0; n count; n ) {TListItem * Li = LStMain-> Items-> add (); node = nodes-> nodes [n] -> childnodes-> nodes [0]; // Get child node's child node, that is, vtip // tip // mode INT M = STRING Node-> getText ()). Toint (); // gets the text content of the corresponding node and converts to int Li-> caption = ""; Li-> ImageIndex = M 5; li-> Subitems-> Add (Nodes -> Nodes [N] -> ChildNodes-> Nodes [1] -> getText ()); li-> Subitems-> add (nodes-> nodes [n] -> childnodes-> nodes [2] -> getText )); // code is the same} LSTMAIN-> items-> endupdate (); after the above code, we see the results similar to the following image: Add a node element: BOOL __FASTCALL TFRMAIN :: AddTask (int M, TdateTime & Date , TDATETIME & TIME, STRING CON {// Todo: Add Your Source Code Here_di_ IXMLNode node = XMLDoc-> DocumentElement; node = node-> AddChild (WideString ( "Tip")); _di_IXMLNode subnode = node-> AddChild (WideString ( "Mode")); subnode-> SetText (WideString (m)); Subnode = node-> addchild ("time"); Subnode-> settext (wide.dateString () "?" time.timeString ()); Subnode = node-> addchild (WideString (" Content ")); Subnode-> setText (WideString (con));} // The above code is easy to understand, when reading, the format of the XML file is finally deleted:

转载请注明原文地址:https://www.9cbs.com/read-128451.html

New Post(0)