Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3432970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:30:58+00:00 2026-05-18T07:30:58+00:00

I have the following XML structure so that I can add my configuration details

  • 0

I have the following XML structure so that I can add my configuration details to lastconnected element:

<?xml version="1.0" encoding="utf-8" ?>
<lastconnectedServers>
</lastconnectedServers >

Now I want to do some XML operation like adding elements and attributes.For Example I want to add the elements to xml above:(Inside elemet lastconnectedServers):

<Server ip="" domain="">
        <SharedFolder name="" type=""/>
        <SharedFolder name="" type =""/>
        <SharedFolder name="" type =""/>
</Server> 

so that the resulting XML will look something like below:

<?xml version="1.0" encoding="utf-8" ?>
<lastconnectedServers>
   <Server ip="" domain="">
        <SharedFolder name="" type=""/>
        <SharedFolder name="" type =""/>
        <SharedFolder name="" type =""/>
   </Server>
</lastconnectedServers >
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:30:58+00:00Added an answer on May 18, 2026 at 7:30 am

    Here is the sample code using MSXML. COM error checking is omitted. for The code looks a little bit wordy because of ATL helpers for COM usage, but the programming model follows W3C DOM APIs which is quite well accepted by xml developers.

    CComPtr<IXMLDOMDocument2> spDoc;
    CComPtr<IXMLDOMElement> spServerElement, spSharedFolderElement;
    CComPtr<IXMLDOMNode> spServerNode, spLastConnectedServerNode;
    IXMLDOMNode* pInsertedNode;
    VARIANT_BOOL varSucc;
    CComBSTR bstrLastConnected = L"<?xml version=\"1.0\" encoding=\"utf-8\" ?> \
                                   <lastconnectedServers> \
                                   </lastconnectedServers >";
    
    spDoc.CoCreateInstance(CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER);
    spDoc->put_async(VARIANT_FALSE);
    spDoc->loadXML(bstrLastConnected, &varSucc);
    
    // Finds the lastConnectedServerNode node with XPath.
    spDoc->selectSingleNode(CComBSTR(L"/lastconnectedServers"),
        &spLastConnectedServerNode);
    
    // Creates and appends Server node.
    spDoc->createElement(CComBSTR(L"Server"), &spServerElement);
    spServerElement->setAttribute(CComBSTR(L"ip"), CComVariant(L""));
    spServerElement->setAttribute(CComBSTR(L"domain"), CComVariant(L""));
    spLastConnectedServerNode->appendChild(spServerElement, &pInsertedNode);
    
    // Creates and appends the first SharedFolder elements.
    spDoc->createElement(CComBSTR(L"SharedFolder"), &spSharedFolderElement);
    spSharedFolderElement->setAttribute(CComBSTR(L"name"), CComVariant(L""));
    spSharedFolderElement->setAttribute(CComBSTR(L"type"), CComVariant(L""));
    spServerElement->appendChild(spSharedFolderElement, &pInsertedNode);
    
    // Creates the second and third SharedFolder elements...
    
    // Gets the xml content.
    CComBSTR bstrXml;
    spDoc->get_xml(&bstrXml);
    
    wprintf(L"%s", (LPCWSTR) bstrXml);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8" ?> <INVOIC02> <IDOC BEGIN="1">
I have the following xml structure : <?xml version=1.0 encoding=utf-8 ?> <nws> <url>http://cpa.hypotheses.org/feed</url> <url>http://news.ycombinator.com/rss</url>
I have the following XML: <?xml version="1.0" encoding="UTF-8"?> <Data> <Set> <Tables> <Table> <Tablehead> <C>Name</C>
I have this XML structure: <?xml version=1.0 encoding=utf-8?> <Request> <RequestHeader requestType=CreateUserRequest dateTime=2011-08-01T16:50:25.9387377+10:00 /> <RequestBody>
I have an XML document that contains the following structure: Its more or less
I have an XML file which describes the data-structure that I can exchange on
I have few very large(10GB) xml files, with the following structure. As you can
I have the following XML structure: <agencies> <city> <name>New York</name> <address>Street A, 101</address> <phone>111-222-333</phone>
I have the following XML structure: <Main> <Node1>Definite</Node1> <Node2>Definite</Node2> <Node3>Definite</Node3> <Node4>Definite</Node4> <Node5>Definite</Node5> <Node6>Definite</Node6> <A>Possible</A>
I have dumped the following XML structure. $VAR1 = { 'events' => {}, 'docvalues'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.