Your UX is waiting ...interact, engage, explore in Las Vegas at CloudWorld 2023

Learn more
Getting elements within nodes in xml via php — Cloud Customer Connect
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Getting elements within nodes in xml via php

Accepted answer
32
Views
4
Comments
edited Jun 8, 2022 12:03PM in General Technical Discussions 4 comments

Content

Hello,

I have the following reponse in xml format:

<n0:Rows>
                     <n0:Row>Plomberie</n0:Row>
                     <n0:Row>Electricité</n0:Row>
                     <n0:Row>Chauffage / Climatisation / Ventilation</n0:Row>
                     <n0:Row>Admin</n0:Row>
                     <n0:Row>Eclairage</n0:Row>

</n0:Rows>

I used the following code:

 $matches = array();
        preg_match("/<n0:Rows>(.*)?<\/n0:Rows>/", html_entity_decode($xml), $matches);
        return $matches[1];

I was able to obtain the following:

                     <n0:Row>Plomberie</n0:Row>
                     <n0:Row>Electricité</n0:Row>
                     <n0:Row>Chauffage / Climatisation / Ventilation</n0:Row>
                     <n0:Row>Admin</n0:Row>
                     <n0:Row>Eclairage</n0:Row>

But i can not separate the elements from the nodes. I have try using DOM and SIMPLEXML. They don't work in my script. How to get the elements? Please note that the number of nodes are not definite. Thanks.

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!