Solved

TinyXML question

Posted on 2010-09-11
2
561 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 …

856 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