8 Replies Latest reply on Aug 16, 2007 8:37 PM by 807605

    XML/ way to count elements ?

    807605
      Hi, i put this question under another post but i thought it would be confusing in answering my question. Is there anyway way for me to be able to count the elements between a tag... like count the <v> tags between each <feature> tags?

      thanks
      <?xml version="1.0" ?> 
           <feature_vector_file>
                  <comments /> 
                 <data_set>
                 <data_set_id>C:\Users\Vas\workspace\AudioAnalysis\data\SP0003.WAV</data_set_id> 
                      <section start="0.0" stop="0.011587301587301587">
                           <feature>
                                 <name>Spectral Centroid</name> 
                                 <v>3.182E0</v> 
                            </feature>
                           <feature>
                                 <name>Spectral Rolloff Point</name> 
                                 <v>2.734E-2</v> 
                            </feature>
                           <feature>
                                 <name>Compactness</name> 
                                 <v>1.126E3</v> 
                            </feature>
                           <feature>
                                 <name>Spectral Variability</name> 
                                 <v>4.998E-4</v> 
                            </feature>
                     </section>
                </data_set>
           </feature_vector_file>
        • 1. Re: XML/ way to count elements ?
          jschellSomeoneStoleMyAlias
          Using XML only? No.

          Using Java, or XSLT, etc? Yes.
          • 2. Re: XML/ way to count elements ?
            807605
            Lol sorry i assumed i posted in java programming it meant java..

            yes java
            • 3. Re: XML/ way to count elements ?
              807605
              Hi, my answer was nt completly answered. I wish to read the number of features <tags> and then set a counter to read the amount of <v> until <= feature amount. And then they ll be another section with the same after that etc .. if that does nt makes sense let me know plz..ill try and be clearer
              • 4. Re: XML/ way to count elements ?
                807605
                i mean read <v>, while the feature count is lower to what i set it ( because the amount of features will vary on each section )
                • 5. Re: XML/ way to count elements ?
                  jschellSomeoneStoleMyAlias
                  There are a number of ways to process XML in java.

                  Once you have a way then that determines how you might want to achieve what you want.

                  So how are you processing it?
                  • 7. Re: XML/ way to count elements ?
                    807605
                    Ah sorry, I am using DOM... for example after name to <v> i do getsNextsibling

                    then there could be more than one <v> value.. i need to read each one. But im having trouble determing how many <v> there are for the program to loop through after it
                    while (count < numberOfFeatures && node.getNodeName().equals("feature")){
                              
                                   Node child = node.getFirstChild();
                                   child = child.getNextSibling();     //gives name
                                   
                                   Node grandChild = child.getNextSibling();
                                   grandChild = grandChild.getNextSibling(); //gets to v
                    
                                   while (grandChild.getNodeName().equals("v")){
                    
                                        Node readChild = grandChild.getFirstChild();
                                        String text = readChild.getNodeValue();//reads value in V
                                        System.out.println(""+ text);
                                                    grandChild = grandChild.getNextSibling();
                                        node = node.getNextSibling();
                                        
                                        }
                    • 8. Re: XML/ way to count elements ?
                      807605
                      jus so you can see it.. there could be mroe <v>
                       <?xml version="1.0" ?> 
                        <!DOCTYPE feature_vector_file (View Source for full doctype...)> 
                      - <feature_vector_file>
                        <comments /> 
                      - <data_set>
                       <data_set_id>C:\Users\Vas\workspace\AudioAnalysis\data\SP0003.WAV</data_set_id> 
                      - <section start="0.0" stop="0.011587301587301587">
                      
                      - <feature>
                        <name>Method of Moments</name> 
                        <v>8.274E-3</v> 
                        <v>1.072E-1</v> 
                        <v>2.732E1</v> 
                        <v>6.961E3</v> 
                        <v>1.774E6</v> 
                        </feature>
                        </section>
                        </data_set>
                        </feature_vector_file>