B
B
bio2015-03-31 04:08:43
PHP
bio, 2015-03-31 04:08:43

How to make a soap xml parser?

There is an xml file with sample content

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header/>
    <soap:Body>
        <m:GetGroupResponse xmlns:m="http://www.test.ru">
            <m:return xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Schedule>
          <Name Name="fret">
            <Groups>
              <Group>
                <Id>0</Id>
                <Name>Name 1</Name>
                <Code>C1</Code>
              </Group>
              <Group>
                <Id>1</Id>
                <Name>Name 2</Name>
                <Code>C2</Code>
              </Group>
            </Groups>
          </Name>
        </Schedule>
        <Schedule>
          <Name Name="fret">
            <Groups>
              <Group>
                <Id>0</Id>
                <Name>Name 1</Name>
                <Code>C1</Code>
              </Group>
              <Group>
                <Id>1</Id>
                <Name>Name 2</Name>
                <Code>C2</Code>
              </Group>
            </Groups>
          </Name>
        </Schedule>
      </m:return>
        </m:GetGroupResponse>
    </soap:Body>
</soap:Envelope>

I need to get an array of Group elements, but I can't get to them in any way.
Tell me how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
olamedia., 2015-03-31
@bioforge

1. you need to register namespaces. in this case, m and soap
php.net/manual/ru/simplexmlelement.registerxpathna...
2. if this is not required by the specification, you can omit intermediate elements with namespaces using xpath search - just by finding all occurrences of Group.

K
KIN1991, 2015-03-31
@KIN1991

For me, doing an API in PHP is a perversion ... There are a lot of libraries in python on this topic ... I advise you to use https://github.com/pavlov99/json-rpc + tornado

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question