How to Create an XMLElement from an external XML response
This is an open discussion with 4 replies, filed under General.
Search
Have you looked at the oEmbed field? You might be able to use their library for the requesting, and just passing in the URL's you got from scraping the text.
@designermonkey I tried to use the DOMDocument but I get this error Argument 1 passed to XMLElement::appendChild() must be an instance of XMLElement, instance of DOMNodeList given
when using the code below. I'm not quite sure how to actually turn either an array or a DOMNodeList into and XMLElement.
$url = "http://vimeo.com/api/oembed.xml?url=".urlencode($video->getAttribute('src')); $doc = new DOMDocument(); $doc - > load($url); $xml = $doc - > getElementsByTagName('oembed'); $xEntry - > appendChild($xml);
@creativedutchmen I am actually already using the oEmbed field for another piece of my site, and I have looked into using their library however it they store the response xml in a column in the database and then it gets merged into the xml output when the datasource is called.
I struggled to figure that out first time too...
$url = "http://vimeo.com/api/oembed.xml?url=".urlencode($video->getAttribute('src')); $doc = new DOMDocument(); $doc->load($url); $xml = $doc->getElementsByTagName('oembed'); $output = $doc->saveXML($xml); $xEntry->appendChild($output);
If I remember right.
Create an account or sign in to comment.
Whats the easiest way to turn an external XML response into an XMLElement that I can append to one of my data sources. I tried a few things and the closest I have come is this:
Which throws the error
XML declaration allowed only at the start of the document in Entity
I have already looked at the remote data source and it seems it does a transform to actually get the data from the response. I was wondering if there is a simpler way. I am using Symphony 2.3.1
A brief background on what I am trying to accomplish is to automatically search the body of my posts for any embed video from YouTube and to send a server request to get oembed data about the links and then append that data to my data source so I can use it to generate Open Graph meta tags, so when a user post a article that contains a video on Facebook they will see a preview of the video and be able to play it without leaving Facebook. Not sure if anyone has done something similar and has an alternate approach.