以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML工具及XML开发环境 』  (http://bbs.xml.org.cn/list.asp?boardid=7)
----  [求助]TinyXml工具的使用  (http://bbs.xml.org.cn/dispbbs.asp?boardid=7&rootid=&id=15843)


--  作者:qgsrg
--  发布时间:3/20/2005 8:36:00 PM

--  [求助]TinyXml工具的使用
各位强人:
   我现在需要在VC6下编写一个xml的编辑器,我初步是想利用TinyXml的对象类,
但我不知道如何使用。麻烦大家谁能给我一个非常简单的小例子即可。比如打开一个xml文件,修改一下里面内容,保存起来就可。

  我一用就出错。不明白怎么回事。。。急切希望大家能帮帮忙。多谢了


--  作者:shanbo198215
--  发布时间:7/20/2005 11:10:00 AM

--  
TiXmlDocument *pDoc = new TiXmlDocument;
pDoc->LoadFile(x.xml,0);

--  作者:xiaostar
--  发布时间:8/11/2005 3:29:00 PM

--  
tinyXML下载的时候附一个test程序,其实都是不错的例子

如:
 const char* demoStart =
  "<?xml version=\"1.0\"  standalone='no' >\n"
  "<!-- Our to do list data -->"
  "<ToDo>\n"
  "<!-- Do I need a secure PDA? -->\n"
  "<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
  "<Item priority=\"2\" distance='none'> Do bills   </Item>"
  "<Item priority=\"2\" distance='far &amp; back'> Look for Evil Dinosaurs! </Item>"
  "</ToDo>";

#ifdef TIXML_USE_STL
 /* What the todo list should look like after processing.
  In stream (no formatting) representation. */
 const char* demoEnd =
  "<?xml version=\"1.0\" standalone=\"no\" ?>"
  "<!-- Our to do list data -->"
  "<ToDo>"
  "<!-- Do I need a secure PDA? -->"
  "<Item priority=\"2\" distance=\"close\">Go to the"
  "<bold>Toy store!"
  "</bold>"
  "</Item>"
  "<Item priority=\"1\" distance=\"far\">Talk to:"
  "<Meeting where=\"School\">"
  "<Attendee name=\"Marple\" position=\"teacher\" />"
  "<Attendee name=\"Voel\
#endif

 // The example parses from the character string (above):
 #if defined( WIN32 ) && defined( TUNE )" position=\"counselor\" />"
  "</Meeting>"
  "<Meeting where=\"Lunch\" />"
  "</Item>"
  "<Item priority=\"2\" distance=\"here\">Do bills"
  "</Item>"
  "</ToDo>";
 QueryPerformanceCounter( (LARGE_INTEGER*) (&start) );
 #endif

 {
  // Write to a file and read it back, to check file I/O.

  TiXmlDocument doc( "demotest.xml" );
  doc.Parse( demoStart );

  if ( doc.Error() )
  {
   printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
   exit( 1 );
  }
  doc.SaveFile();
 }

 TiXmlDocument doc( "demotest.xml" );
 bool loadOkay = doc.LoadFile();

 if ( !loadOkay )
 {
  printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
  exit( 1 );
 }

 printf( "** Demo doc read from disk: ** \n\n" );
 doc.Print( stdout );

 TiXmlNode* node = 0;
 TiXmlElement* todoElement = 0;
 TiXmlElement* itemElement = 0;


 // --------------------------------------------------------
 // An example of changing existing attributes, and removing
 // an element from the document.
 // --------------------------------------------------------

 // Get the "ToDo" element.
 // It is a child of the document, and can be selected by name.
 node = doc.FirstChild( "ToDo" );
 assert( node );
 todoElement = node->ToElement();
 assert( todoElement  );

 // Going to the toy store is now our second priority...
 // So set the "priority" attribute of the first item in the list.
 node = todoElement->FirstChildElement(); // This skips the "PDA" comment.
 assert( node );
 itemElement = node->ToElement();
 assert( itemElement  );
 itemElement->SetAttribute( "priority", 2 );

 // Change the distance to "doing bills" from
 // "none" to "here". It's the next sibling element.
 itemElement = itemElement->NextSiblingElement();
 assert( itemElement );
 itemElement->SetAttribute( "distance", "here" );

 // Remove the "Look for Evil Dinosours!" item.
 // It is 1 more sibling away. We ask the parent to remove
 // a particular child.
 itemElement = itemElement->NextSiblingElement();
 todoElement->RemoveChild( itemElement );

 itemElement = 0;

 // --------------------------------------------------------
 // What follows is an example of created elements and text
 // nodes and adding them to the document.
 // --------------------------------------------------------

 // Add some meetings.
 TiXmlElement item( "Item" );
 item.SetAttribute( "priority", "1" );
 item.SetAttribute( "distance", "far" );

 TiXmlText text( "Talk to:" );

 TiXmlElement meeting1( "Meeting" );
 meeting1.SetAttribute( "where", "School" );

 TiXmlElement meeting2( "Meeting" );
 meeting2.SetAttribute( "where", "Lunch" );

 TiXmlElement attendee1( "Attendee" );
 attendee1.SetAttribute( "name", "Marple" );
 attendee1.SetAttribute( "position", "teacher" );

 TiXmlElement attendee2( "Attendee" );
 attendee2.SetAttribute( "name", "Voel" );
 attendee2.SetAttribute( "position", "counselor" );

 // Assemble the nodes we've created:
 meeting1.InsertEndChild( attendee1 );
 meeting1.InsertEndChild( attendee2 );

 item.InsertEndChild( text );
 item.InsertEndChild( meeting1 );
 item.InsertEndChild( meeting2 );

 // And add the node to the existing list after the first child.
 node = todoElement->FirstChild( "Item" );
 assert( node );
 itemElement = node->ToElement();
 assert( itemElement );

 todoElement->InsertAfterChild( itemElement, item );

 printf( "\n** Demo doc processed: ** \n\n" );
 doc.Print( stdout );
我只贴了一部份


--  作者:77i01
--  发布时间:11/4/2005 4:53:00 PM

--  
我也想在VC .net 2003里面用这个东西,可是我把
tinystr.h
tinyxml.h
tinystr.cpp
tinyxml.cpp
tinyxmlerror.cpp
tinyxmlparser.cpp
六个文件包含到项目中,任何代码都没有加。一编译就出错了。
提示是:

------ 已启动全部重新生成: 项目: Win32XML, 配置: Debug Win32 ------

正在删除项目“Win32XML”(配置“Debug|Win32”)的中间文件和输出文件。
正在编译...
stdafx.cpp
正在编译...
tinyxmlparser.cpp
d:\试验机资料\xml\win32xml\tinyxmlparser.cpp(1573) : fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾
tinyxmlerror.cpp
d:\试验机资料\xml\win32xml\tinyxmlerror.cpp(53) : fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾
tinyxml.cpp
d:\试验机资料\xml\win32xml\tinyxml.cpp(1733) : fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾
tinystr.cpp
d:\试验机资料\xml\win32xml\tinystr.cpp(116) : fatal error C1010: 在查找预编译头指令时遇到意外的文件结尾
TempTest.cpp
Win32XML.cpp
正在生成代码...

生成日志保存在“file://d:\试验机资料\Xml\Win32XML\Debug\BuildLog.htm”中
Win32XML - 4 错误,0 警告


---------------------- 完成 ---------------------

    全部重新生成: 0 已成功, 1 已失败, 0 已跳过

怎么回事啊??老大们给我一个提示。。


--  作者:wispx
--  发布时间:11/15/2005 11:11:00 AM

--  
我想在linux下用tinyxml 修改一个xml文件的element
./a.out story info 就把里面一个节点的的element story 改成了 info

但是应当怎么个使用法呢?


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms