Solved

TinyXML question

Posted on 2010-09-11
2
555 Views
Last Modified: 2012-05-10
Hello,
please give me some hint how to write a node like:
"<METADATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">"
with TinyXML. A normal node I write like attached code sample.

Ocrana
void xmldata::AddNodeAndText( TiXmlNode* pParent, const char* pszNodeName, const std::wstring &text )
{
	TiXmlElement* pElem = new TiXmlElement( pszNodeName ); // the new node/element

	char* pszText = new char[ (int) text.size() + 1 ];
	::WideCharToMultiByte( CP_ACP, 0, text.c_str(), (int) text.size() + 1, 
		pszText, (int) text.size() + 1, NULL, NULL  );

	// add the text
	TiXmlText *pText = new TiXmlText( pszText	);
	pElem->LinkEndChild( pText );

	pParent->LinkEndChild( pElem ); // add it to parent well

	delete [] pszText;
}

Open in new window

0
Comment
Question by:Ocrana
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 33655064
I am a bit rusty here, but IIRC that should be like
	TiXmlElement* pElem = new TiXmlElement ( "METADATA");

	pElem->SetAttribute ( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"");
	pElem->SetAttribute ( "xmlns:xsd", "http://www.w3.org/2001/XMLSchema");

Open in new window

0
 

Author Closing Comment

by:Ocrana
ID: 33749960
Great solution. Thanks!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question