0

So far I can display the

<group number=

and

<category number= 

How can i display

<category label= attributes for each category?

Xml

<?xml version="1.0" encoding="UTF-8"?>
<outputTree xmlns="http://www.ibm.com/software/analytics/spss/xml/oms" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ibm.com/software/analytics/spss/xml/oms http://www.ibm.com/software/analytics/spss/xml/oms/spss-output-1.8.xsd">
  <command command="Summarize" displayOutlineValues="label" displayOutlineVariables="label" displayTableValues="label" displayTableVariables="label" lang="en" text="Summarize">
    <pivotTable subType="Report" text="Batch Processing Report">
      <dimension axis="row" text="Cases">
        <group label="Test Site" text="Test Site" varName="PLANT_DESC" variable="true">
          <group hide="true" text="A">
            <group string="A" text="AA" varName="PLANT_DESC">
              <group label="Product" text="Product" varName="PROD_DESC" variable="true">
                <group hide="true" text="A">
                  <group string="S" text="S" varName="PROD_DESC">
                    <group label="Batch Number" text="Batch Number" varName="BATCH_NO" variable="true">
                      <group hide="true" text="A">
                        <group number="3704542" text="3704542" varName="BATCH_NO">
                          <category number="1" text="1">
                            <dimension axis="column" text="Variables">
                              <category label="Batch Run" text="Batch Run" varName="BATCH_RUN_ID" variable="true">
                                <cell number="4202" text="4202" varName="BATCH_RUN_ID"/>
                              </category>
                              <category label="Application" text="Application" varName="APP_ID" variable="true">
                                <cell label="Calibration" number="101" text="Calibration" varName="APP_ID"/>
                              </category>
                            </dimension>
                          </category>
                          <category number="2" text="2">
                            <dimension axis="column" text="Variables">
                              <category label="Batch Run" text="Batch Run" varName="BATCH_RUN_ID" variable="true">
                                <cell number="4341" text="4341" varName="BATCH_RUN_ID"/>
                              </category>
                              <category label="Application" text="Application" varName="APP_ID" variable="true">
                                <cell label="Range Setting" number="201" text="Range Setting" varName="APP_ID"/>
                              </category>
                            </dimension>
                          </category>
                        </group>
                      </group>
                    </group>
                  </group>
                </group>
              </group>
            </group>
          </group>
        </group>
      </dimension>
    </pivotTable>
  </command>
</outputTree>

C

private void GetXMLData1()
{
    try
    {
        XNamespace ns = "http://www.ibm.com/software/analytics/spss/xml/oms";
        XDocument testXML = XDocument.Load(@"C:\Users\byilmaz\Desktop\SPSS_SITE\test.xml");

        var cats = from cat in testXML.Descendants(ns + "dimension").Where
                   (cat => (string)cat.Attribute("axis") == "column" && (string)cat.Attribute("text") == "Variables")

                   select new
                       {
                           BATCH_NO = cat.Parent.Parent.Attribute("number").Value,
                           RUN_NO = cat.Parent.Attribute("number").Value,                                   
                       }
                       ;

        foreach (var cat in cats)
        {
            //xmlTitle.Text += "Group Name: " + cat.groupName + " and Cat Id: " + cat.catId + " and Cat Name: " + cat.catName + " and Cat Cell: " + cat.catCell + "</br>";

            xmlTitle.Text += "BATCH_NO: " + cat.BATCH_NO + " </br>";
            xmlTitle.Text += "RUN_NO: " + cat.RUN_NO + " </br><hr>";
        }

    }
    catch (Exception err)
    {
        throw (err);
    }
}

Output

enter image description here

1 Answer 1

1

You used Descendants() at the beginning, why not use them for the categories too?

select new
         {
             BATCH_NO = cat.Parent.Parent.Attribute("number").Value,
             RUN_NO = cat.Parent.Attribute("number").Value,
             InnerCategories = cat.Descendants(ns + "category").Select(c => c.Attribute("label").Value)
         };

and then in the foreach loop you have:

foreach (var cat in cats)
{
   //xmlTitle.Text += "Group Name: " + cat.groupName + " and Cat Id: " + cat.catId + " and Cat Name: " + cat.catName + " and Cat Cell: " + cat.catCell + "</br>";

     xmlTitle.Text += "BATCH_NO: " + cat.BATCH_NO + " </br>";
     xmlTitle.Text += "RUN_NO: " + cat.RUN_NO + " </br><hr>";


     foreach (string s in cat.InnerCategories )
     {
        // process them one by one 
     }

     // or print them at once

     string joinedInnerCats = string.Join(",", cat.InnerCategories);
     xmlTitle.Text += string.Format("Categories: {0}", joinedInnerCats);
 }
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks alot Rosen, how do i do the inner foreach loop? can you show me any example?
I updated my post. In the context of your usage, I guess you will have to use them where you display the Batch No and Run No maybe?
i mean how will i get the value in the inner loop?
string s (defined in the loop) represents the value of the current category in the loop. cat.InnerCategories will contain 2 items - strings "Batch Run" and "Application" in your example (the values of the label attribute).
Thanks alot, i will check it tomorrow.

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.