Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to traverse through every tag #180

Open
Vetagiri-Hrushikesh opened this issue Jan 19, 2022 · 0 comments
Open

How to traverse through every tag #180

Vetagiri-Hrushikesh opened this issue Jan 19, 2022 · 0 comments

Comments

@Vetagiri-Hrushikesh
Copy link

Hello Team
I have an xml something structured like this. I can loop through only var tags if I use this code given below. I need everything which is inside message in order. Can someone please help me with this?

<data>
    <message>
        <var />
        <var />
        <bitfield>
                <bit />
                <bit />
                <bit />
        </bitfield>
        <var />
        <var />
        <var />
        <var />
       <bitfield>
                <bit />
                <bit />
                <bit />
                <bit />
                <bit />
                <bit />
        </bitfield>
    </message>
</data>

    fetch('../assets/filename.xml').then((response) => {
      response.text().then((xml) => {
        let result1 = converter.xml2json(xml, { compact: true, spaces: 4});
        const JSONData = JSON.parse(result1);
        // console.log(JSONData);
        let list: any = [];
        list = Array.isArray(JSONData.data.message.var) ? JSONData.data.message.var : [];
        for (let i of list) {
          let varTag = {
            addr: i._attributes.addr ? i._attributes.addr : '',
            len: i._attributes.len ? i._attributes.len : '',
            name: i._attributes.name ? i._attributes.name : '',
          }
          this.list.push(varTag);
        }
        console.log(this.list);
      });
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant