godzilla
godzilla

Reputation: 3125

how do i add attributes to xml using xerces?

i have currently generated some XML using xercer in C++, using the following code:

           XMLCh tempAttribute[100];
           XMLString::transcode("ad", tempStr, 99);
           doc = impl->createDocument(0,tempStr ,0);
           root = doc->getDocumentElement();
           XMLString::transcode("imageAd", tempStr, 99);
           element = doc->createElement(tempStr);
           root->appendChild(element);

However i am attempting to get the attributes within the top "ad" element (as below), however i have had little luck in doing so, can someone with experience using xerces please advise.

Thanks in advance!

<ad xsi:noNamespaceSchemaLocation="smaato_ad_v0.9.xsd" modelVersion="0.9">
    <imageAd>

Upvotes: 1

Views: 1727

Answers (1)

Clemens
Clemens

Reputation: 1817

maybe you didn't saw the call to setAttribute in my previous answer but you can set any attribute for any element with calls like

root->setAttribute(L"modelVersion", L"0.9");
root->setAttribute(L"xsi:noNamespaceSchemaLocation", L"xsi:noNamespaceSchemaLocation");

Where root is the pointer to your root element.

Upvotes: 1

Related Questions