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 7993795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:57:31+00:00 2026-06-04T13:57:31+00:00

So I have a file that already exists, and I read this file and

  • 0

So I have a file that already exists, and I read this file and add some nodes to it. Due to the nature of the processing required, I have my code in a loop, so for each row in a given data table, I open the existing file, write my new nodes, and close the file.

The first iteration inserts the node group perfectly. Every iteration thereafter is problematic and somehow adds to the first grouping instead of creating its own grouping.

This is what each grouping should look like and this is how it generates the first one:

  <item identifier="ITEM-F2D7FEDF240B4DCCBF346DBE2C47AC89" identifierref="RES-770DCE40C5BA4E97B1E3B3DB49BBBD4F" isvisible="true" parameters="">
    <title>Title1</title>
    <adlcp:datafromlms xmlns:adlcp="http://www.imsproject.org/xsd/imscp_rootv1p1p2">
    </adlcp:datafromlms>
  </item>

Once the whole thing is processed though, it ends up looking like this:

  <item identifier="ITEM-F2D7FEDF240B4DCCBF346DBE2C47AC89" identifierref="RES-770DCE40C5BA4E97B1E3B3DB49BBBD4F" isvisible="true" parameters="">
    <title>Title1</title>
    <adlcp:datafromlms xmlns:adlcp="http://www.imsproject.org/xsd/imscp_rootv1p1p2">
    </adlcp:datafromlms>
    <title>Title2</title>
    <adlcp:datafromlms xmlns:adlcp="http://www.imsproject.org/xsd/imscp_rootv1p1p2">
    </adlcp:datafromlms>
    <title>Title3</title>
    <adlcp:datafromlms xmlns:adlcp="http://www.imsproject.org/xsd/imscp_rootv1p1p2">
    </adlcp:datafromlms>
    <title>Title4</title>
    <adlcp:datafromlms xmlns:adlcp="http://www.imsproject.org/xsd/imscp_rootv1p1p2">
    </adlcp:datafromlms>
    <title>Title5</title>
    <adlcp:datafromlms xmlns:adlcp="http://www.imsproject.org/xsd/imscp_rootv1p1p2">
    </adlcp:datafromlms>
  </item>
  <item identifier="ITEM-4D80AFFE59D04E2188F39908B9325961" identifierref="RES-A9CFDC9208714DAF9EA351D4656A7EBC" isvisible="true" parameters="" />
  <item identifier="ITEM-F4EDB38AD0D74CC38722E6D1A8D67E24" identifierref="RES-E2F92D4C5165482386421944053EE933" isvisible="true" parameters="" />
  <item identifier="ITEM-BF1C7474919B4B22BC300F98034ABDD1" identifierref="RES-8A0ED1C94CA44A71A07A8A4A5DA2A528" isvisible="true" parameters="" />
  <item identifier="ITEM-156731B2ABB14AB29135CBF5D8CBCFF3" identifierref="RES-D452D539C49A4D65BC3A8AC6B16DE718" isvisible="true" parameters="" />

So basically it ends up tacking the bulk of the new data into the existing node (where I don’t want it) and creating the new item node at the bottom of the organization group (which is where it should be). I need the title and adlcp entries to be attached under each of the new item nodes.

Here’s the code I’m using. Remember that this code gets executed multiple times upon the same file, once for each set of entries. There’s an additional node created by the code that goes into another place called resources, but that part works fine so I didn’t include it in the XML excerpts above.

            string strItem = Guid.NewGuid().ToString("N").ToUpper(); // GUID for random unique value.
            string strRes = Guid.NewGuid().ToString("N").ToUpper(); // GUID for random unique value.

            XmlDocument docXMLFile = new XmlDocument();
            docXMLFile.Load(resultPath + "imsmanifest.xml"); // Load file

            #region Item Element Creation
            XmlNode xItem = docXMLFile.CreateNode(XmlNodeType.Element, "item", docXMLFile.DocumentElement.NamespaceURI);
            XmlAttribute xIdentifier = docXMLFile.CreateAttribute("identifier");
            XmlAttribute xIdentifierRef = docXMLFile.CreateAttribute("identifierref");
            XmlAttribute xIsVisible = docXMLFile.CreateAttribute("isvisible");
            XmlAttribute xParameters = docXMLFile.CreateAttribute("parameters");
            xIdentifier.Value = "ITEM-" + strItem;
            xIdentifierRef.Value = "RES-" + strRes;
            xIsVisible.Value = "true";
            xParameters.Value = "";

            xItem.Attributes.Append(xIdentifier);
            xItem.Attributes.Append(xIdentifierRef);
            xItem.Attributes.Append(xIsVisible);
            xItem.Attributes.Append(xParameters);

            // NOTE - the docXMLFile.DocumentElement.NamespaceURI GETS RID OF XMLNS="" WHICH IS BULLSHIT.
            XmlNode xTitle = docXMLFile.CreateNode(XmlNodeType.Element, "title", docXMLFile.DocumentElement.NamespaceURI);

            if ((dataRow["product_name"].ToString() + " - " + dataRow["topic_name"].ToString()).Count() > 255)
                xTitle.InnerText = (dataRow["product_name"].ToString() + " - " + dataRow["topic_name"].ToString()).Substring(0, 255);
            else
                xTitle.InnerText = dataRow["product_name"].ToString() + " - " + dataRow["topic_name"].ToString();

            XmlNode xADLCPDataFromLMS = docXMLFile.CreateNode(XmlNodeType.Element, "adlcp:datafromlms", docXMLFile.DocumentElement.NamespaceURI);
            xADLCPDataFromLMS.InnerText = dataRow["datafromlms"].ToString();

            // This is where the new stuff gets inserted.
            docXMLFile.GetElementsByTagName("organization")[0].InsertAfter(xItem, docXMLFile.GetElementsByTagName("organization")[0].LastChild);
            docXMLFile.GetElementsByTagName("item")[0].InsertAfter(xTitle, docXMLFile.GetElementsByTagName("item")[0].LastChild);
            docXMLFile.GetElementsByTagName("item")[0].InsertAfter(xADLCPDataFromLMS, docXMLFile.GetElementsByTagName("item")[0].LastChild);
            #endregion

            #region Resource Element Creation
            XmlNode xResource = docXMLFile.CreateNode(XmlNodeType.Element, "resource", docXMLFile.DocumentElement.NamespaceURI);
            XmlAttribute xRefIdentifier = docXMLFile.CreateAttribute("identifier");
            XmlAttribute xRefADLCP = docXMLFile.CreateAttribute("adlcp:scormtype");
            XmlAttribute xRefHREF = docXMLFile.CreateAttribute("href");
            XmlAttribute xRefType = docXMLFile.CreateAttribute("type");
            xRefIdentifier.Value = "RES-" + strRes;
            xRefADLCP.Value = "sco";
            xRefHREF.Value = dataRow["launch_url"].ToString().ToLower();
            xRefType.Value = "webcontent";

            xResource.Attributes.Append(xRefIdentifier);
            xResource.Attributes.Append(xRefADLCP);
            xResource.Attributes.Append(xRefHREF);
            xResource.Attributes.Append(xRefType);

            docXMLFile.GetElementsByTagName("resources")[0].InsertAfter(xResource, docXMLFile.GetElementsByTagName("resources")[0].LastChild);
            #endregion

            docXMLFile.Save(resultPath + "imsmanifest.xml"); //save
  • 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-06-04T13:57:32+00:00Added an answer on June 4, 2026 at 1:57 pm

    Well this is the problem:

    docXMLFile.GetElementsByTagName("item")[0]
              .InsertAfter(xTitle,
                           docXMLFile.GetElementsByTagName("item")[0].LastChild);
    docXMLFile.GetElementsByTagName("item")[0]
              .InsertAfter(xADLCPDataFromLMS, 
                           docXMLFile.GetElementsByTagName("item")[0].LastChild);
    

    You’re explicitly using the first item element. I suspect you really just want:

    xItem.AppendChild(xTitle);
    xItem.AppendChild(xADLCPDataFromLMS);
    

    After all, you do what to append the elements to the newly created item element, right?

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

Sidebar

Related Questions

I have an exe that already creates a csv file. If I save the
All Gmail users should have already noticed that file upload progress bar has been
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus
I have a file that contains this <!-- CordovaVersion --> I want to replace
I have my code below. It correctly reads my sqlite database file(that i have
I have some code which iteratively appends data to a file and looks similar
I have read other questions on this topic but none that actually answers my
I have a file that looks like: 1 1 C C 1.9873 2.347 3.88776
I have a file that has the following format: 12345 TAB_HERE Name : The
I have a file that can be any thing like ZIP, RAR, txt, CSV,

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.