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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:29:18+00:00 2026-06-12T19:29:18+00:00

I have a large XML file (converted to JSON) that consists of multiple repeating

  • 0

I have a large XML file (converted to JSON) that consists of multiple repeating sections with the same structure. Each section has a set of identically structured attribues (XML to JSON conversion moves all attributes into an object called myAttributes) in addition to the section specific properties. My objective is to be able to read existing XML and generate new XML.

I tried to use the mapping plugin, put it only allows me to read XML, not generate it, plus there are multiple interdependencies between object elements.

I figured that the best way to work around this is to pre-define a set of objects that match small sections of the XML. When assembled together, these objects would be able to generate XML structure that i need. This way I can either loop though the JSON array that I generated from XML, populate objects that I pre-defined with appropriate data and append them to my viewModel (lets say 10 alerts, 3 actions, 6 metric groupings, etc). Generating XML from pre-defined objects should also be easy.

However, due to my general inexperience with both JavaScrip and KnockoutJS, I am having a very hard time figuring this one out.

// Main Top Level Management Module Object
function ManagementModule(data) {
    this.myAttributes = new Object();
    this.myAttributes.Name = ko.observable(data.Name);
    this.myAttributes.IsActive = ko.observable(data.IsActive);
    this.myAttributes.DescriptionContentType = ko.observable(data.DescriptionContentType);
    this.myAttributes.Description = ko.observable(data.Description);
    // There are other object specific properties, but I omitted them for now
}

// New Alert Object. It will be deep in the hierarchy of the main top level object
// but for now i will make it top level for test purposes.
function Alert(data) {
    this.myAttributes = new Object();
    this.myAttributes.Name = ko.observable(data.Name);
    this.myAttributes.IsActive = ko.observable(data.IsActive);
    this.myAttributes.DescriptionContentType = ko.observable(data.DescriptionContentType);
    this.myAttributes.Description = ko.observable(data.Description);
    // There are other object specific properties, but I omitted them for now
}

// View Model
function myModel() {
    var self = this;
    self.ManagementModule = ko.observableArray();
    self.Alerts = ko.observableArray();
};
var myViewModel = new myModel();

Then I loop through my JSON and try to append things to the view model… and this is where things do not work right. Perhaps because I misunderstand the objects…

$.getJSON("/getXML", function (data) {

    for (var key in data) {
        // Do something here
    }

    // This seems to work OK. There is only 1 so, I just
    // set it.
    myViewModel.ManagementModule(data['myAttributes']);

    for (var i = 0; i < data['DataGroups']['DataGroup'].length; i++) {
        var current = data['DataGroups']['DataGroup'][i];
        if(current['AlertBase']) {

             var AlertBase = current['AlertBase'];

             // There are multiple Alarts
             for (var i = 0; i < AlertBase.length; i++) {
                     myViewModel.Alerts.push(Alert(AlertBase[i].myAttributes));
             }
        }

    };
    ko.applyBindings(myViewModel);

});

This kinda-sorta works…. When I try to bind to it

<div data-bind="text: Alerts.myAttributes.Name"></div>
<div data-bind="text: ManagementModule.myAttributes.Name"></div>

it is not working. If i bind like this:

<div data-bind="text: myAttributes.Name"></div>

it outputs both, myViewModel.ManagementModuleName.myAttributes.Name and the very last one myViewModel.Alert.myAttributes.Name joined together.

What am I doing wrong? How can I assemble a viewModel out of multiple nested objects?

UPDATE: Just realized I was binding incorrectly, but that still produces a bunch of
myViewModel.ManagementModuleName.myAttributes.Name and the very last one myViewModel.Alert.myAttributes.Name joined together

<div data-bind="foreach: Alerts()">
    <div data-bind="text: myAttributes.Name"></div>
</div>

And I think I solved it…

myViewModel = new ManagementModule(data['myAttributes']);

myViewModel.Alerts = ko.observableArray();
myViewModel.Alerts.push(new Alert(AlertBase[i].myAttributes));


<div data-bind="text: myAttributes.Name"></div><br />
<div data-bind="foreach: Alerts()">
    <div data-bind="text: myAttributes.Name"></div>
</div>
  • 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-12T19:29:20+00:00Added an answer on June 12, 2026 at 7:29 pm

    For starters, you are referencing observableArrays as if they we observables. You need a data-bind=foreach: Alarms() in there someplace.

    OK: See if this jsFiddle helps you: http://jsfiddle.net/8QVe6/

    Note that I made the properties camelCased (i.e. managementModule).

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

Sidebar

Related Questions

I have a large xml file (>30mb) that has paths such as yoursite.com/category/section/3389121/title-article I
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
I have a large XML file (many MBs) that I cannot afford to download
I have a large xml file that looks like this: 20120124 07:30:15.301, saving to
I have a request that returns a large xml file. I have the file
I have a large xml file (40 Gb) that I need to split into
I have a very large XML file that I need to parse so I
I have a large XML file that looks like <data> skdfnlsniisimsoinfsdfoisdfinsdofinodnfonf <emrosem> 23324097234097g </emrosem>
I have a function, that gets a large XML file, then parses it, and
I have a large XML file (180 megs or so) that has lots of

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.