locked
help with reading XML RRS feed

  • Question

  • User1324715958 posted

    Pretty sure I'm missing something really small. I'm trying to dig down into the category and grab data. I have discovered the issue but I don't know the solution. 

    Here is the xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <Products type="array">
      <DesignAndConstruction>
    <product> <prd_code>055385</prd_code> <prd_name>The Joplin Tornado: Emergency Preparedness and Beyond</prd_name> <prd_description>Includes a 30-minute video detailing the hospital’s response during the Joplin tornado plus three other videos, one each from the perspectives of hospital administrators, clinicians, and facility staff.</prd_description> </product>
    </DesignAndConstruction> <EnvironmentalServices>
    <product> <prd_code>057034</prd_code> <prd_name>Practice Guidance for Healthcare Environmental Cleaning, Second Edition (Print Format)</prd_name> <prd_description>This publication, prepared by AHE and edited by infection control professionals contains the recommended practices for environmental cleaning in healthcare facilities.</prd_description> </product>
    </EnvironmentalServices> <CodingAndBilling>
    <product> <prd_code>148069</prd_code> <prd_name>ICD-10-CM and ICD-10-PCS Coding Handbook with Answers, 2018 Rev. Ed. Print Format</prd_name> <prd_description>Handbook content reflects 2017 versions of the Official Guidelines for Coding and Reporting as well as AHA Coding Clinic® for ICD-10-CM and ICD-10-PCS content published through May 2017. Update: </prd_description> </product>
    </CodingAndBilling> </Products>

    Here is my loop code snippet

    //Environmental Services
    $(xml).find('EnvironmentalServices').each(function() {
        $(xml).find('Product').each(function() {
            //Add Product Names To List								 
            $(this).find("prd_name").each(function() {
                var name = $(this).text();
                DataList.push(String(name));
            });
    
            //Add Product Codes To List
            $(this).find("prd_code").each(function() {
                var code = $(this).text();
                DataList.push(String(code));
            });
    
            //Add Product Descriptions To List
            $(this).find("prd_description").each(function() {
                var description = $(this).text();
                DataList.push(String(description));
            });
        });
    });

    I only want the info for "Environmental Services" but it gives me all the products. If I remove "products" it will work. How do I get this to work with the current format? Thanks 

    Wednesday, August 1, 2018 3:55 PM

Answers

  • User1324715958 posted

    I found my mistake:

    //Environmental Services
    $(xml).find('EnvironmentalServices Product').each(function() {
        //Add Product Names To List								 
        $(this).find("prd_name").each(function() {
            var name = $(this).text();
            DataList.push(String(name));
        });
    
        //Add Product Codes To List
        $(this).find("prd_code").each(function() {
            var code = $(this).text();
            DataList.push(String(code));
        });
    
        //Add Product Descriptions To List
        $(this).find("prd_description").each(function() {
            var description = $(this).text();
            DataList.push(String(description));
        });
    });



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 1, 2018 4:27 PM