Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

378
Views
How to get the specific attribute "folder_name" value from XML & store it in an array in React js?

    class LoadXml extends React.Component {
      constructor() {
        super();
        this.state = { total_page: null, menu_array: [] };
      }
    
      componentDidMount() {
        axios
          .get("/xml/menu.xml", {
            "Content-Type": "application/xml; charset=utf-8",
          })
          .then((res) => {
            const jsonDataFromXml = new XMLParser().parseFromString(res.data);
            console.log(jsonDataFromXml);
    
            this.setState({ total_page: jsonDataFromXml.getElementsByTagName("page").length });
            this.setState({ menu_array: jsonDataFromXml.getElementsByTagName("page")[0].getAttribute("folder_name") });
          });
      }
    
      componentDidUpdate() {
        var totalPage = this.state.total_page;
        //localStorage.setItem("TotalPage", totalPage);
        console.log(`Total number of Pages: ${totalPage}`);
      }
    
      render() {
        return (
          <div>
            <h1>Total Pages: {this.state.total_page}</h1>
            <h1>Total Pages: {this.state.menu_array}</h1>
          </div>
        );
      }
    }

folder_name="page1">

I am trying to get the xml data in React JS. In JS I can get the attribute value using getAttribute() but I am not sure how to do that in React. Please guide me.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!