0

the snippt shows the XML detail : please referes to the image, shows the table...

<ExtractSummaryDateSet>
      <_date>2017-09-20</_date>
      <_portfolioSummaries>
        <ExtractSummaryDateSetDetail>
          <_portfolioName>52613661_CL</_portfolioName>
          <_detail>
         
            <Before>0</Before>
            <After>-329</After>
            <ChangeMaturing>0</ChangeMaturing>
            <ChangeNew>-329</ChangeNew>
            
           
          </_detail>
        </ExtractSummaryDateSetDetail>
        <ExtractSummaryDateSetDetail>
          <_portfolioName>52613661_LP</_portfolioName>
          <_detail>
           
         
            <Before>0</Before>
            <After>-329</After>
            <ChangeMaturing>0</ChangeMaturing>
            <ChangeNew>-329</ChangeNew>
         
          </_detail>
        </ExtractSummaryDateSetDetail>
        <ExtractSummaryDateSetDetail>
          <_portfolioName>526136|Total</_portfolioName>
          <_detail>
         
            <Before>0</Before>
            <After>-329</After>
            <ChangeMaturing>0</ChangeMaturing>
            <ChangeNew>-329</ChangeNew>
            
           
          </_detail>
        </ExtractSummaryDateSetDetail>

I am trying to use 2 Dimential arrays in XML to create a table HTML

        for (var i = 0; i < x.length; i++){
                  var row= x[i];
                  var date = row.getElementsByTagName("Date")[0].childNodes[0].nodeValue;
        for(var j = 0;j < row.length; j++){

            var  before = row[j].getElementsByTagName("Before")[0].childNodes[0].nodeValue; 
            var  after = row[j].getElementsByTagName("after")[0].childNodes[0].nodeValue; 
    }
}

just wanna know is the example above semantically correct?
in the second array can i use row[j] to call the array

for (var y = 0; y < x.length; y++){


for (var i = 0; i < x[i].length; i++){

    table_summary +="<th></th><th></th><td>" + x[y][j].getElementsByTagName("_date")[0].childNodes[0].nodeValue + "</td>" ;

}

how do I pass the value correctly? x[y][i] can't not find the value.

enter image description here

2
  • can I request you put a sample of your XML on here? Commented Sep 28, 2017 at 9:25
  • and how are you paring your XML? Commented Sep 28, 2017 at 9:47

2 Answers 2

1

I am working on XML format in web application and encounter to similar your issue. You can transform XML to HTML like your method but create HTML tags from XML is very cumbersome.

I suggest you use XSLT for this transform.

I created a simple XSLT for your XML and converted this transform very easily.

Please see Online transform and click html in result panel to see HTML output for your XML.

Sign up to request clarification or add additional context in comments.

Comments

0

You can consider a multi dimensional array as an array of arrays.

so this is fine :

for (var i = 0; i < x.length; i++){
    var row= x[i]

    for(var j = 0;j < row.length; j++){
        var  before = row[j];
    }
}

However you can also write this as :

for (var i = 0; i < x.length; i++) {
    for(var j = 0;j < x[i].length; j++) {
        var  before = x[i][j];
    }
}

12 Comments

yes but it wouldnt work on Ajax / JS i call it like this var after = row[j].getElementsByTagName("after")[0].childNodes[0].nodeValue;
have you tried debugging what you get back for each method call? colsole.log(row[j]); colsole.log(row[j].getElementsByTagName("after")); etc.
my second loop return nth ... what is going to be the issue?
have you tried debugging row? is it actually an array?
I put down the XML file
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.