0

I'm trying to use the XML API for Cisco IOS XR (Docs: Cisco IOS XR XML API Guide, Cisco IOS XR Release 4.1) but I'm not sure what library to use in PHP (simpleXML?) to just open a TCP connection to a port on a device and start reading and writing XML to it.

I understand the concept of the schemas and such, but everything I can find about PHP and XML seems to be oriented towards web services, POST, etc, and this is simply reading and writing XML.

hakre
  • 193,403
  • 52
  • 435
  • 836
Aaron
  • 148
  • 11
  • This language is not what you're looking for. Move along, move along. – STT LCU May 21 '13 at 15:25
  • SimpleXML is for XML, connections are either via sockets or streams in PHP. So depending what you actually ask for, the answer differs. Please elaborate. Are you able to establish a TCP connection with your router already? If so, please add the code to your question. If not, add the code as well to your question and highlight where you hit the roadblock. – hakre May 21 '13 at 17:27
  • @hakre I haven't done the part to use sockets to communicate with the equipment - but I don't really expect that to be all that complicated on the face of it. I'm more wondering once I get that output back from socket_recv, what do I feed it into? Although it looks like simplexml_load_string is what I'm looking for there – Aaron May 21 '13 at 18:18
  • @STTLCU can you be more specific? Are you referring to PHP or XML as not what I'm looking for? – Aaron May 21 '13 at 18:18
  • 1
    Well for XML parsing (and creating), you can start with SimpleXML: http://php.net/simplexml.examples-basic - It should cover everything well for that API out of the box. For the transport layer you need to write the sockets part your own. I still would prefer you hack together some code, so you can leave it as an answer here on the site. Even if only exemplary. Let me know if you've got problems formulating the request with SimpleXML or parsing the response. – hakre May 21 '13 at 18:25
  • I wouldn't use PHP because PHP is not for interactivity but it's much more suited to standalone scripts. AKA: if you need to do batches of operations with little or no user interaction, PHP is ok, I would use it too. But if you need a lot of interaction with your user, I'd look for something else, @Aaron – STT LCU May 22 '13 at 06:32

1 Answers1

0

What you mean is opening, reading and writing to a socket. Read the documentation on this subject for more information. The xml is just an accessory to your actual communications, which will happen, one way or another, via sockets.

EDIT: And thus you will not need any library since sockets are part of php by default.

webmaster777
  • 1,442
  • 2
  • 12
  • 17
  • So it sounds like all of the I/O to get the XML in and out of the program is via the socket. Once I get it into there, what's the best bet to read and write the XML, either for user display, or writing for equipment configuration? SimpleXML + ? – Aaron May 21 '13 at 18:20
  • I'd like to refer to hakre's [comment](http://stackoverflow.com/questions/16673477/how-can-i-send-xml-to-a-tcp-port-and-have-a-conversation-there-using-php/16673672#comment23996996_16673477) on this matter. Yes, SimpleXML is one of the solutions for this. But start coding and see how far you get is absolutely necessary for us to help you further! – webmaster777 May 22 '13 at 08:22