problem is the following:
I have an xml file with data and I am looking for a small part of the data to write it into a new file: content has been shortened by request:
snippet if type=dhcp-client:
<deviceconfig> <system> <type> <dhcp-client> <send-hostname>yes</send-hostname> </dhcp-client> </type> <hostname>Firewall</hostname> </system> </deviceconfig>
snippet if type=static
<deviceconfig> <system> <type> <static/> </type> <hostname>Firewall</hostname> <permitted-ip> <entry name="192.168.0.0/24"/> </permitted-ip> <ip-address>192.168.0.2</ip-address> <netmask>255.255.255.0</netmask> <default-gateway>192.168.0.1</default-gateway> </system> <network> <interface> <ethernet> <entry name="ethernet1/1"> <layer3> <ip> <entry name="192.168.0.5/24"/> </ip> </layer3> </entry> </ethernet> </interface> <virtual-router> <entry name="default"> <routing-table> <ip> <static-route> <entry name="default-route"> <nexthop> <ip-address>192.168.0.1</ip-address> </nexthop> <interface>ethernet1/4</interface> <destination>0.0.0.0/0</destination> </entry> </static-route> </ip> </routing-table> </entry> </virtual-router> </network>
the four relevant values are unique (or nonexistent) within the "system" tag <system></system>
things like ip-address might appear again elsewhere outside of <system></system>
but i am only checking for the ones inside system, if the type is not static dont appear, i set it to dhcp-client
this is what I need as a result in a file if the type is dhcp:
type=dhcp-client
this is what I need as a result in a file if the type was static:
type=static ip-address=192.168.0.2 default-gateway=192.168.0.1 netmask=255.255.255.0
I am not sure how to accomplish this efficiently and integrated inside an existing PHP file (so either work with exec or better yet use php only).
I am also limited to tools that are installed by default on an ubuntu server system and would be unable to use other packages.
PS: this is actually the whole/complete use-case, I will not need to produce other output other than these two examples. Thanks for any help or pointers :)