Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
fw:txml [2008/05/25 20:51] alfred |
fw:txml [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 33: | Línea 33: | ||
| ===== Escritura ===== | ===== Escritura ===== | ||
| + | |||
| Línea 57: | Línea 58: | ||
| <?xml version="1.0" ?> | <?xml version="1.0" ?> | ||
| <Hello>World</Hello> | <Hello>World</Hello> | ||
| + | </code> | ||
| + | Otro ejemplo: | ||
| + | <code cpp> | ||
| + | TiXmlDocument doc; | ||
| + | TiXmlElement* msg; | ||
| + | |||
| + | TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" ); | ||
| + | doc.LinkEndChild( decl ); | ||
| + | |||
| + | TiXmlElement * root = new TiXmlElement( "MyApp" ); | ||
| + | doc.LinkEndChild( root ); | ||
| + | |||
| + | msg = new TiXmlElement( "Welcome" ); | ||
| + | msg->LinkEndChild( new TiXmlText( "Welcome to MyApp" )); | ||
| + | root->LinkEndChild( msg ); | ||
| + | |||
| + | msg = new TiXmlElement( "Farewell" ); | ||
| + | msg->LinkEndChild( new TiXmlText( "Thank you for using MyApp" )); | ||
| + | root->LinkEndChild( msg ); | ||
| + | ... | ||
| </code> | </code> | ||
| Línea 127: | Línea 148: | ||
| ===== Como... ===== | ===== Como... ===== | ||
| + | |||
| ==== Insertar un comentario ==== | ==== Insertar un comentario ==== | ||
| + | Se crea un objeto ''TiXmlComment'' y le añadimos el texto mediante su método ''SetValue''. | ||
| + | <code cpp> | ||
| + | TiXmlComment * comment = new TiXmlComment(); | ||
| + | comment->SetValue(" Settings for MyApp " ); | ||
| + | root->LinkEndChild( comment ); | ||
| + | </code> | ||
| + | |||
| ==== Utilizar el TiXmlHandle ==== | ==== Utilizar el TiXmlHandle ==== | ||
| + | Es una forma más sencilla de acceder a los elementos permitiendo acceder directamente a sus hijos. | ||
| + | <code cpp> | ||
| + | TiXmlHandle docHandle( &document ); | ||
| + | TiXmlElement* child2 = docHandle.FirstChild("Document").FirstChild("Element").Child("Child", 1).ToElement(); | ||
| + | </code> | ||
| + | <code cpp> | ||
| + | int i=0; | ||
| + | while () { | ||
| + | TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); | ||
| + | if ( !child ) | ||
| + | break; | ||
| + | i++; | ||
| + | } | ||
| + | </code> | ||
| ==== Enlazar una clase a un archivo .xml ==== | ==== Enlazar una clase a un archivo .xml ==== | ||
| Evidentemente puedes hacerlo manualmente, pero la forma más sencilla es utilizando [[http://sourceforge.net/projects/tinybind|TinyBind]]. | Evidentemente puedes hacerlo manualmente, pero la forma más sencilla es utilizando [[http://sourceforge.net/projects/tinybind|TinyBind]]. | ||