[SalesForce] How to get all the child text from a xml file

I need to get all the values from child node

            <fields>
            <field1>Name</field1>
            <csv1>field1</csv1>
            </fields>

But i am not able to get then at a single loop i need to loop 2 times to get the values my code

 for(Dom.XMLNode subchild : child.getChildElements()) 
            {
                system.debug('Sub child ' + subchild.getText() );
                for(Dom.XMLNode subchildfield : subchild.getChildren())
                {
                    system.debug('Sub child Field ' + subchildfield.getText() );
                    fName  = subchildfield.getText();
                    fieldName.add(fName);
                    //fileValuesXML.add(fieldName);
                    //system.debug('Filed Name in XML field  ' + fieldName);
                }

                system.debug('Filed Name before affing to filevalueXML  ' + fieldName);                    
                fileValuesXML.add(fieldName);
                fieldName.clear();
                system.debug('Filed Name after affing to filevalueXML  ' + fileValuesXML);
            }

is it possible to get all the child node values at a single loop so that i can have it in a map. Please guide me

Related Topic