void CTinyXMLAttributeExchangingObject::addString(const string& name, const string& attribute)
{
	TiXmlText* myElement = new TiXmlText(name.c_str());
	myElement->SetValue(attribute.c_str());
	
	mRoot->LinkEndChild(myElement);
}
Example #2
0
void Configuration::setConfigSetting(string sectionName, string settingName, string settingValue)
{
	TiXmlElement* setting = findConfigSetting(sectionName, settingName);
	if (setting)
	{
		TiXmlText* settingText = setting->ToText();
		if (settingText)
			settingText->SetValue(settingValue);
	}
	else
	{
		// Check to see if the section exists
		TiXmlHandle docHandle(&configs);
		TiXmlElement* newSection = docHandle.FirstChild("osdb").FirstChild(sectionName).ToElement();
		if (!newSection)
		{
			newSection = new TiXmlElement(sectionName);
			configs.RootElement()->LinkEndChild(newSection);
		}

		TiXmlElement* newSettingElement = new TiXmlElement(settingName);
		newSettingElement->LinkEndChild(new TiXmlText(settingValue));
		newSection->LinkEndChild(newSettingElement);
	}

	saveConfig();
}
Example #3
0
/**************************************************************************
* name       : ModifyElemValue
* description: 修改元素值
* input      : pszElemValue 元素值
* output     : NA
* return     : NA
* remark     : NA
**************************************************************************/
void CXml::ModifyElemValue(const char *pszElemValue)
{
    if (NULL == pszElemValue)
    {
        return;
    }

    if (NULL == m_pXmlNode)
    {
        return;
    }

	if (NULL == m_pXmlNode->FirstChild())
	{
		(void)SetElemValue(pszElemValue);
		return;
	}

    TiXmlText *pXmlText = m_pXmlNode->FirstChild()->ToText();

    //判断指针是否为空
    if (NULL == pXmlText)
    {
        return;
    }

    pXmlText->SetValue(pszElemValue);
}
Example #4
0
void CXml::ModifyElemValueCDATA(const char *pszElemValue)
{
	if (NULL == pszElemValue)
	{
		return;
	}

	if (NULL == m_pXmlNode)
	{
		return;
	}

	TiXmlText *pXmlText = m_pXmlNode->FirstChild()->ToText();

    //判断指针是否为空
    CHECK_POINTER_VOID(pXmlText);

	pXmlText->SetCDATA(true);  // 添加CDATA属性
	pXmlText->SetValue(pszElemValue);
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool XmlElementImpl::setValueText(const String& text)
{
    TiXmlText* pText = NULL;
    TiXmlNode* pNode = NULL;
    for (pNode = FirstChild(); pNode; pNode = pNode->NextSibling())
    {
        pText = pNode->ToText();
        if (pText) break;
    }

    cvf::CharArray charArr = text.toUtf8();

    if (pText) 
    {
       pText->SetValue(charArr.ptr());
    }
    else
    {
        pText = new TiXmlText(charArr.ptr());
        LinkEndChild(pText);
    }

    return true;
}
Example #6
0
void IXMLConfigProperty::set(const std::string& value)
{
	TiXmlText* text = mPElement->FirstChild()->ToText();
	if (text != NULL)
		text->SetValue(value.c_str());
}
Example #7
0
std::string Kml::PointPlacemark(  TiXmlElement* document, RoutePoint* routepoint ) {
    TiXmlElement* pmPoint = new TiXmlElement( "Placemark" );
    document->LinkEndChild( pmPoint );
    TiXmlElement* pmPointName = new TiXmlElement( "name" );
    pmPoint->LinkEndChild( pmPointName );
    TiXmlText* pmPointNameVal = new TiXmlText( routepoint->GetName().mb_str( wxConvUTF8 ) );
    pmPointName->LinkEndChild( pmPointNameVal );

    TiXmlElement* pointDescr = new TiXmlElement( "description" );
    pmPoint->LinkEndChild( pointDescr );

    bool descrIsPlainText = true;
    wxCharBuffer descrString = routepoint->m_MarkDescription.mb_str( wxConvUTF8 );

    if( insertQtVlmExtendedData ) {
        // Does the RoutePoint description parse as XML with an <ExtendedData> root tag?
        TiXmlDocument descrDoc;
        TiXmlElement* extendedData;
        if( descrDoc.Parse( descrString, 0, TIXML_ENCODING_UTF8 ) ) {
            if( 0 == strncmp( descrDoc.RootElement()->Value(), "ExtendedData", 12 ) ) {
                descrIsPlainText = false;
                extendedData = descrDoc.RootElement();
                TiXmlHandle docHandle( &descrDoc );
                TiXmlElement* seq = docHandle.FirstChild( "ExtendedData" ).FirstChild( "vlm:sequence" ).ToElement();
                if( ! seq ) {
                    seq = new TiXmlElement( "vlm:sequence" );
                    TiXmlText* snVal = new TiXmlText(
                            wxString::Format( _T("%04d"), seqCounter ).mb_str( wxConvUTF8 ) );
                    seq->LinkEndChild( snVal );
                    descrDoc.RootElement()->LinkEndChild( seq );
                }
                pmPoint->LinkEndChild( descrDoc.RootElement()->Clone() );
            }
        }
        if( descrIsPlainText ) {
            // We want Sequence names but there was some non-parsing stuff in the description.
            // Push that into a sub-tag of an XML formatted description.
            extendedData = new TiXmlElement( "ExtendedData" );
            pmPoint->LinkEndChild( extendedData );
            TiXmlElement* seq = new TiXmlElement( "vlm:sequence" );
            extendedData->LinkEndChild( seq );
            TiXmlText* snVal = new TiXmlText(
                    wxString::Format( _T("%04d"), seqCounter ).mb_str( wxConvUTF8 ) );
            seq->LinkEndChild( snVal );

            if( routepoint->m_MarkDescription.Length() ) {
                TiXmlElement* data = new TiXmlElement( "Data" );
                data->SetAttribute( "name", "Description" );
                extendedData->LinkEndChild( data );

                TiXmlElement* value = new TiXmlElement( "value" );
                data->LinkEndChild( value );
                TiXmlText* txtVal = new TiXmlText( descrString );
                value->LinkEndChild( txtVal );
            }
        }
        if( extendedData && seqCounter == 0 ) {
            const wxCharBuffer ownshipPos = wxString::Format( _T("%f %f"), gLon, gLat ).mb_str( wxConvUTF8 );
            TiXmlHandle h( extendedData );
            TiXmlElement* route = h.FirstChild( "vlm:route" ).ToElement();
            TiXmlElement* ownship = h.FirstChild( "vlm:route" ).FirstChild( "ownship" ).ToElement();
            if( route ) {
                if( ownship ) {
                    TiXmlText* owns = ownship->FirstChild()->ToText();
                    if( owns ) {
                        owns->SetValue( ownshipPos );
                    } else {
                        owns = new TiXmlText( ownshipPos );
                        ownship->LinkEndChild( owns );
                    }
                } else {
                    ownship = new TiXmlElement( "ownship" );
                    route->LinkEndChild( ownship );
                    TiXmlText* owns = new TiXmlText( ownshipPos );
                    ownship->LinkEndChild( owns );
                }
            } else {
                route = new TiXmlElement( "vlm:route" );
                extendedData->LinkEndChild( route );
                ownship = new TiXmlElement( "ownship" );
                route->LinkEndChild( ownship );
                TiXmlText* owns = new TiXmlText( ownshipPos );
                ownship->LinkEndChild( owns );
            }
        }
    }

    else {
        // Add description as dumb text.
        TiXmlText* pointDescrVal = new TiXmlText( descrString );
        pointDescr->LinkEndChild( pointDescrVal );
    }

    TiXmlElement* point = new TiXmlElement( "Point" );
    pmPoint->LinkEndChild( point );

    TiXmlElement* pointCoord = new TiXmlElement( "coordinates" );
    point->LinkEndChild( pointCoord );

    std::stringstream pointCoordStr;
    pointCoordStr << routepoint->m_lon << "," << routepoint->m_lat << ",0. ";

    TiXmlText* pointText = new TiXmlText( pointCoordStr.str() );
    pointCoord->LinkEndChild( pointText );

    return pointCoordStr.str();
}
Example #8
0
int main()
{
	//
	// We start with the 'demoStart' todo list. Process it. And
	// should hopefully end up with the todo list as illustrated.
	//
	const char* demoStart = 
		"<?xml version=\"1.0\"  standalone='no' >\n"
		"<!-- Our to do list \n data -->"
		"<ToDo>\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'> Look for Evil Dinosaurs! </Item>"
		"</ToDo>";

	/* What the todo list should look like after processing.

		<?xml version="1.0" standalone="no" ?>
		<!-- Our to do list data -->
		<ToDo>
		    <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="Voo" position="counselor" />
		        </Meeting>
		        <Meeting where="Lunch" />
		    </Item>
		    <Item priority="2" distance="here"> Do bills
		    </Item>
		</ToDo>
	*/

	// The example parses from the character string (above):

	{
		// 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().c_str(), doc.ErrorDesc().c_str() );
			exit( 1 );
		}
		doc.SaveFile();
	}

	TiXmlDocument doc( "demotest.xml" );
	doc.LoadFile();

	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->FirstChild();
	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();
	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;
	text.SetValue( "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", "Voo" );
	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 );

	// --------------------------------------------------------
	// Different ways to walk the XML document.
	// --------------------------------------------------------

	int count = 0;
	TiXmlElement*	element;

	// Walk all the top level nodes of the document.
	count = 0;
	for( node = doc.FirstChild();
		 node;
		 node = node->NextSibling() )
	{
		count++;
	}
	printf( "The document contains %d top level nodes. (3)\n", count );


	// Walk all the top level nodes of the document,
	// using a different sytax.
	count = 0;
	for( node = doc.IterateChildren( 0 );
		 node;
		 node = doc.IterateChildren( node ) )
	{
		count++;
	}
	printf( "The document contains %d top level nodes. (3)\n", count );


	// Walk all the elements in a node.
	count = 0;
	for( element = todoElement->FirstChildElement();
		 element;
		 element = element->NextSiblingElement() )
	{
		count++;
	}
	printf( "The 'ToDo' element contains %d elements. (3)\n", count );


	// Walk all the elements in a node by value.
	count = 0;
	for( node = todoElement->FirstChild( "Item" );
		 node;
		 node = node->NextSibling( "Item" ) )
	{
		count++;
	}
	printf( "The 'ToDo' element contains %d nodes with the value of 'Item'. (3)\n", count );
	
	/*
	for( int i=0; i<1000; i++ )	
		doc.LoadFile( "SmallRuleset1.xml" );
	doc.SaveFile( "smalltest.xml" );
 	*/
	return 0;
}