Serve mp4 file through coldfusion and play with jwplayer - ios

I have an web application in coldfusion which record videos and serve videos to user.
The video is working fine on android and desktop browsers but it is giving me error "Error loading media: File could not be played" in IOS.
Here is my JWPlayer code which is currently working.
jwplayer("element").setup({
file: "/video.cfm?token=4514_129_9B2F727D-5056-A85D-6EBE3E48FC2AB9C6",
image: "path/to/image",
width: 450,
height: 360,
type: "mp4",
logo: {
file: 'path/to/logo',
link: 'example.com',
hide : true
}
});
Here is my video.cfm to server mp4 after verification.
<cfset videoFile = 'path\to\file'>
<cfset fileInfo = GetFileInfo(videoFile)>
<cfset length = fileInfo.size>
<cfset start = 0>
<cfset end = fileInfo.size - 1>
<cfheader name="Content-type" value="video/mp4">
<cfheader name="Accept-Ranges" value="0-#length#">
<cfheader name="Content-Range" value="bytes #start#-#end#/#fileInfo.size#">
<cfheader name="Content-Length" value="#length#">
<cfcontent file="#videoFile#" type="video/mp4">
I have tried some solution by adding some header. But that doesn't work. Can anyone help me to sort out the problem.

I am able to resolve my problem. iOS uses a partial content header to run videos. Thanks to rickward for this lovely solution: Media Delivery to iPhones and iPads. I have made some little changes and it started working for me.
Here is the final video.cfm file.
<cfset videoPath = 'path\to\mp4\file'>
<cfif FileExists(videoPath)>
<cfset fileInfoVar = GetFileInfo(videoPath)>
<cfheader name="Last-Modified" value="#fileInfoVar.Lastmodified#">
<cfheader name="ETag" value="#hash(videoPath, 'MD5')#">
<cfheader name="Content-Location" value="http://example.com/video.cfm">
<cfif structKeyExists(GetHttpRequestData().headers, 'Range')>
<cfset rangeDownload(videoPath)>
<cfelse>
<cffile action="readbinary" file="#videoPath#" variable="theData">
<cfscript>
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
response.setContentType("video/mp4");
response.setContentLength(arrayLen(theData));
out = response.getOutputStream();
out.write(theData);
out.flush();
out.close();
</cfscript>
</cfif>
</cfif>
<cffunction name="rangeDownload" returnType="void" output="yes">
<cfargument name="file" type="string" required="true" hint="path to file">
<cfset var l = {}>
<cfset l.request = GetHttpRequestData()>
<cffile action="readbinary" file="#ARGUMENTS.file#" variable="l.theData">
<cfset l.size = arrayLen(l.theData)>
<cfset l.length = l.size>
<cfset l.start = 0>
<cfset l.end = l.size - 1>
<!--- Now that we've gotten so far without errors we send the accept range header
/* At the moment we only support single ranges.
* Multiple ranges requires some more work to ensure it works correctly
* and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
*
* Multirange support annouces itself with:
* header('Accept-Ranges: bytes');
*
* Multirange content must be sent with multipart/byteranges mediatype,
* (mediatype = mimetype)
* as well as a boundry header to indicate the various chunks of data.
*/
--->
<cfheader name="Accept-Ranges" value="0-#l.length#">
<!---<cfheader name="Accept-Ranges" value="bytes"> --->
<!---
multipart/byteranges
http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 --->
<cfif structKeyExists(l.request.headers, 'Range')>
<cfset l.c_start = l.start>
<cfset l.c_end = l.end>
<!--- Extract the range string --->
<cfset l.range = ListGetAt(l.request.headers.range, 2, '=')>
<!--- Make sure the client hasn't sent us a multibyte range --->
<cflog file="rangeDownload" text="#l.range#" />
<cfif l.range contains ','>
<!--- (?) Should this be issued here, or should the first
range be used? Or should the header be ignored and
we output the whole content?
--->
<cfheader statusCode = "416" statusText = "Requested Range Not Satisfiable">
<cfheader name="Content-Range" value="bytes #l.start#-#l.end#/#l.size#">
<!--- (?) Echo some info to the client? --->
<cfabort>
</cfif>
<!--- If the range starts with an '-' we start from the beginning
If not, we forward the file pointer
And make sure to get the end byte if specified --->
<cfif Left(l.range, 1) eq '-'>
<!--- The n-number of the last bytes is requested --->
<cfset l.c_start = l.size - Mid(l.range, 2, Len(l.range))>
<cfelse>
<cfset l.rangeArray = ListToArray(l.range, '-')>
<cfset l.c_start = l.rangeArray[1]>
<cfif ArrayLen(l.rangeArray) eq 2 and val(l.rangeArray[2]) gt 0>
<cfset l.c_end = l.rangeArray[2]>
<cfelse>
<cfset l.c_end = l.size>
</cfif>
</cfif>
<!---
/* Check the range and make sure it's treated according to the specs.
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
*/
// End bytes can not be larger than l.end. --->
<cfif l.c_end gt l.end>
<cfset l.c_end = l.end>
</cfif>
<!--- Validate the requested range and return an error if it's not correct. --->
<cfif l.c_start gt l.c_end || l.c_start gt (l.size - 1) || l.c_end gte l.size>
<cfheader statusCode = "416" statusText = "Requested Range Not Satisfiable">
<cfheader name="Content-Range" value="bytes #l.start#-#l.end#/#l.size#">
<!--- (?) Echo some info to the client? --->
<cfabort>
</cfif>
<cfset l.start = l.c_start>
<cfset l.end = l.c_end>
<cfset l.length = l.end - l.start + 1><!--- Calculate new content length --->
<cfscript>
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
response.setContentType("video/mp4");
response.setContentLength(l.length);
</cfscript>
<cfheader statusCode = "206" statusText = "Partial Content">
</cfif>
<!--- Notify the client the byte range we'll be outputting --->
<cfheader name="Content-Range" value="bytes #l.start#-#l.end#/#l.size#">
<cfheader name="Content-Length" value="#l.length#">
<cfscript>
// Start buffered download
out = response.getOutputStream();
// write the portion requested
out.write(l.theData, javacast('int', l.start), javacast('int', l.length));
out.flush();
out.close();
</cfscript>
</cffunction>

Related

ColdFusion : String : Get Price From Inside 2 Points

I'm playing with the NOMICS API and get data in a string. But I'm having trouble getting just the Price:
This is part of the string from the METHOD=GET - which works fine..
"currency":"SHIB","platform_currency":"ETH","price":"0.000026199726","price_date":"2022-02-06T00:00:00Z","price_timestamp":"
I know that ,"price":" is the lead and then "," is the end...
But I can't seem to get just the 0.000026199726 from the middle- which is what I need.
<CFHTTP METHOD="Get"
URL="https://api.nomics.com/v1/currencies/ticker?key=#apikey#&ids=SHIB">
<cfset feedData = cfhttp.filecontent>
<cfset startpos = findNoCase(',"price":"', feedData)>
<cfset endpos = findNoCase('",', feedData)>
<cfset getdata = mid(feeddata,startpos,endpos-startpos)
<b>#getdata#</b> Errors as neg number.
The value of parameter 3 of the function Mid, which is now -191, must be a non-negative integer
This has to be an easy task. I must be using the wrong string function?
EDIT: Figured out - it was finding the "," but they are so many of them it found first one, which put things negative - so fix was to find the structure after. ","price_date" is after.
<cfset string = cfhttp.filecontent>
<cfset startpos = findNoCase('price":"', string)>
<cfset endpos = findNoCase('","price_date"', string)>
<cfset detdata = mid(string,startpos,endpos-startpos)>
<cfoutput>
start: #startpos#<br>
end: #endpos#<br>
data: #detdata#<br>
trimmed data: #trim(detdata)#<br>
trimmed data:
<br><b>#removechars(detdata,1,8)#</b><br><br>
</cfoutput>
I'll look at the JSON examples as well. Perhaps that will help with multiple pulls.
Excellent Folks : Thank you so much
<CFHTTP METHOD="Get"
URL="https://api.nomics.com/v1/currencies/ticker?key=#apikey#&ids=SHIB,BTC">
<cfset output = cfhttp.filecontent>
<cfoutput>
<cfset arrayOfStructs = deserializeJson(output)>
<cfloop array="#arrayOfStructs#" index="getpr">
<cfset Price = getpr.price />
<cfset TKID = getpr.id />
#tkid#: #price#<br>
</cfloop>
</cfoutput>
Spits out:
BTC: 43963.45841296
SHIB: 0.000033272664
Credit to Andrea/SOS
<CFHTTP METHOD="Get"
URL="https://api.nomics.com/v1/currencies/ticker?key=#apikey#&ids=SHIB,BTC">
<cfset output = cfhttp.filecontent>
<cfoutput>
<cfset arrayOfStructs = deserializeJson(output)>
<cfloop array="#arrayOfStructs#" index="getpr">
<cfset Price = getpr.price />
<cfset TKID = getpr.id />
#tkid#: #price#<br>
</cfloop>
</cfoutput>

How do I iterate xml files that have many of the same tag per record? [duplicate]

This question already has an answer here:
VBScript iterating through XML child nodes and retrieving values
(1 answer)
Closed 2 years ago.
I'm working on an old classic asp system that receives an xml file from another system that has recently changed the format of the xml file. It contains a video library summary I need to parse.
Sample xml as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<videodb>
<version>1</version>
<movie>
<title>3 Days to Kill</title>
<ratings>
<rating name="themoviedb" max="10" default="true">
<value>6.000000</value>
<votes>1416</votes>
</rating>
</ratings>
<plot>A dangerous international spy... blah blah blah</plot>
<runtime>113</runtime>
<mpaa>Rated PG-13</mpaa>
<id>tt2172934</id>
<uniqueid type="imdb" default="true">tt2172934</uniqueid>
<uniqueid type="tmdb">192102</uniqueid>
<genre>Action</genre>
<genre>Drama</genre>
<genre>Thriller</genre>
<genre>Crime</genre>
<year>2014</year>
<status></status>
<code></code>
<trailer></trailer>
<actor>
<name>Kevin Costner</name>
<role>Ethan Renner</role>
</actor>
<actor>
<name>Amber Heard</name>
<role>Vivi Delay</role>
</actor>
<dateadded>2014-12-21 14:31:07</dateadded>
</movie>
<movie>
<title>47 Ronin</title>
<ratings>
<rating name="themoviedb" max="10" default="true">
<value>6.000000</value>
<votes>2324</votes>
</rating>
</ratings>
<plot>Kai—an outcast—joins Oishi, the leader of 47 outcast samurai...blah blah blah</plot>
<runtime>119</runtime>
<mpaa>Rated PG-13</mpaa>
<playcount>1</playcount>
<lastplayed>2020-03-24</lastplayed>
<id>tt1335975</id>
<uniqueid type="imdb" default="true">tt1335975</uniqueid>
<uniqueid type="tmdb">64686</uniqueid>
<genre>Drama</genre>
<genre>Action</genre>
<genre>Adventure</genre>
<genre>Fantasy</genre>
<year>2013</year>
<trailer></trailer>
<actor>
<name>Keanu Reeves</name>
<role>Kai</role>
</actor>
<actor>
<name>Hiroyuki Sanada</name>
<role>Kuranosuke Ôishi</role>
</actor>
<dateadded>2014-12-21 22:15:42</dateadded>
</movie>
</videodb>
My asp code is as follows....
Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load Server.MapPath("/MovieLibrary/data/videodb.xml")
Dim xmlMovies
Set xmlMovies = objXMLDoc.documentElement.selectNodes("movie")
For Each xmlMovie In xmlMovies
'
Dim title:title = xmlMovie.selectSingleNode("title").text
Dim rating_value:rating_value = left(xmlMovie.selectSingleNode("ratings/rating/value").text,3)
Dim rating_votes:rating_votes = xmlMovie.selectSingleNode("ratings/rating/votes").text
Dim plot:plot = xmlMovie.selectSingleNode("plot").text
Dim runtime:runtime = xmlMovie.selectSingleNode("runtime").text
Dim mpaa_rating:mpaa_rating = xmlMovie.selectSingleNode("mpaa").text
Dim release_year:release_year = xmlMovie.selectSingleNode("year").text
Dim id:id = xmlMovie.selectSingleNode("id").text
Dim genre:genre = xmlMovie.selectSingleNode("genre").text
Dim date_added:date_added = xmlMovie.selectSingleNode("dateadded").text
Dim actor:actor = xmlMovie.selectSingleNode("actor/name").text
Response.Write Server.HTMLEncode(title) & " "
Response.Write Server.HTMLEncode(rating_value) & "/10 "
Response.Write Server.HTMLEncode(rating_votes) & "<br>"
Response.Write Server.HTMLEncode(plot) & "<br>"
Response.Write Server.HTMLEncode(runtime) & " Minutes "
Response.Write Server.HTMLEncode(mpaa_rating) & " "
Response.Write Server.HTMLEncode(release_year) & " "
Response.Write Server.HTMLEncode(id) & "<br> "
Response.Write Server.HTMLEncode(genre) & "<br>"
Response.Write Server.HTMLEncode(date_added) & "<br>"
Response.Write Server.HTMLEncode(actor) & "<br><br>"
Next
As you can see in the xml file each movie can have several "genre" entries and several "actor" entries. I can get all the entries but I can only get the first "genre" entry and the first "actor" entry. I'm having trouble figuring out how to create a sub-list of the genres listed for each movie so I can push them into my class....and I only want to grab the first 2 or three actors, not 27 as some do.
Obviously I need to create an array for the genre and actor fields but everything I try comes back with something like "this collection doesn't have this method" or nothing at all.
I know my code is messy, this is a test bed I created to make sure I can pull the new format of the file.
Any help will be appreciated. (sorry for the long post)
Use a function to get the text using selectNodes Method
Function getNodeValue(nodename)
Dim NodeValue : NodeValue = ""
Dim Nodes
set Nodes = xmlMovie.selectNodes(nodename)
For each Node in Nodes
If NodeValue = "" Then
NodeValue = Node.Text
Else
NodeValue = NodeValue & ", " & Node.Text
End If
Next
getNodeValue = NodeValue
End Function
This will return a comma delimited string.
Now you can get all the values like:
Dim title:title = getNodeValue("title")
and
Dim genre:genre = getNodeValue("genre")

how to parse a xml in erlang?

I have this string with xml extract in a tuple list:
MessageResponse = [{"code",0},{"description","description"},{"respuestaServicioSoap",{{"executeWebServiceSolutionResult",{{"CEDULARUCSpecified", false},{"AUTORIZACION", "00000012431781"},{"AUTORIZACIONSpecified",true},{"RESULTADO","000"},{"CODIGO_RESULTADOSpecified",true},{"COD_PAGO","00000012431781"},{"COD_PAGOSpecified",true},{"COMISION",{{"string","0"}}},{"COMISIONSpecified", true},{"DIRECCIONSpecified", false},{"FECHA_COMPENSACIONSpecified", false},{"FECHA_TRANSACCION","20170116"},{"FECHA_TRANSACCIONSpecified",true},{"FECHORA_SW","20170116123951"},{"FECHORA_SWSpecified",true},{"HORA_TRANSACCION","123951"},{"HORA_TRANSACCIONSpecified",true},{"MENSAJE","TRANSACCION OK"},{"MENSAJESpecified",true},{"NOMBRESpecified",false},{"PRODUCTO","0010761005"},{"PRODUCTOSpecified",true},{"SECUENCIA_ADQ","2833"},{"SECUENCIA_ADQSpecified",true},{"SECUENCIA_SW","576167"},{"SECUENCIA_SWSpecified",true},{"TERMINAL","0696069603000001"},{"TERMINALSpecified",true},{"TYPE_TRNSpecified",false},{"VALOR_TOTAL", { { "string", "0" }}},{"VALOR_TOTALSpecified",true},{"XML_ADDSpecified",false},{"XML_DATASpecified",false},{"XML_FACT","<XML_FACT>\r\n <DATOS_FACT>\r\n <LINEA_1>REPRESENTACIONES ORMAN S.A.</LINEA_1>\r\n <LINEA_2>RUC: 0987654321</LINEA_2>\r\n <LINEA_3 />\r\n <LINEA_4 />\r\n <LINEA_5>FACTURA: 001-627-0000048745</LINEA_5>\r\n <LINEA_6>CLAVE: </LINEA_6>\r\n <LINEA_7>COMISION POR SERVICIO</LINEA_7>\r\n <LINEA_8>RECAUDACION EEAAPP - CUENTA: 11223344</LINEA_8>\r\n <LINEA_12>FACTURA: 001-627-0000048745 - CONSULTE SU DOCUMENTO EN WWW.LITO.COM/DOCUMENTOSELECTRONICOS</LINEA_12>\r\n <MSGCOMP />\r\n <MSGFACT />\r\n </DATOS_FACT>\r\n</XML_FACT>"},{"XML_FACTSpecified",true},{"XML_REPLY_CONSULTASpecified",false},{"XML_REPLY_PAGOSSpecified",false}}},{"executeWebServiceSolutionResultSpecified", true}}},{"result", "ok"}]
and need to get the text in LINEA_5 tag, any idea how to do it?
with this code:
{Xml, _Rest} = xmerl_scan:string(XmlFactura).
[#xmlText{value=Linea5}] = xmerl_xpath:string("//LINEA_5/text()", Xml).
the OTP library xmerl provides all the functions to manipulate XML files or string. It provides a set of record that help to handle different elements.
documentation is available here
The records are defined in erlXX/lib/xmerl-YYY/include/xmerl.hrl:
#xmlText{}
#xmlElement{}
#xmlPI{}
#xmlComment{}
#xmlDecl{}
[edit]
The xml data that you provide in your example is already modified, so I take an example from my own. Consider an xml file with the content:
<?xml version="1.0" encoding="UTF-8"?> <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="uuid_id">
<metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:creator opf:role="aut" opf:file-as="Ahern, Cecelia">Cecelia Ahern</dc:creator>
<dc:publisher>J'ai Lu</dc:publisher>
<meta name="calibre:title_sort" content="Si tu me voyais maintenant"/>
<dc:description>description blah blah</dc:description>
<meta name="calibre:timestamp" content="2012-03-18T18:04:20+00:00"/>
<dc:title>Si tu me voyais maintenant</dc:title>
<meta name="cover" content="cover"/>
<dc:date>2012-03-18T18:04:23+00:00</dc:date>
<dc:contributor opf:role="bkp">calibre (0.8.42) [http://calibre-ebook.com]</dc:contributor>
<dc:identifier opf:scheme="ISBN">9782290006504</dc:identifier>
<dc:identifier id="uuid_id" opf:scheme="uuid">7d062b17-258e-4268-9d46-a753c063c969</dc:identifier>
<dc:subject>Chick-lit</dc:subject>
<meta name="calibre:user_categories" content="{}"/>
<meta name="calibre:author_link_map" content="{"Cecelia Ahern": ""}"/>
<dc:language>fr</dc:language>
</metadata>
<manifest>
<item href="cover.jpeg" id="cover" media-type="image/jpeg"/>
</manifest>
<spine toc="ncx">
<itemref idref="titlepage"/>
</spine>
<guide>
<reference href="titlepage.xhtml" type="cover" title="Cover"/>
</guide> </package>
It is extract from an epub book, and stored in a file "content.opf". If I want to get the author name (line 4) I can do:
1> rr("C:\\My programs\\erl8.2\\lib\\xmerl-1.3.12\\include\\xmerl.hrl").
2> {Xml,_} = xmerl_scan:file("../doc/content.opf"),
2> Content = Xml#xmlElement.content,
2> [MetaRec] = [X || X <- Content, X#xmlElement.name == metadata],
2> Meta = MetaRec#xmlElement.content,
2> [CreatRec] = [X || X <- Meta, X#xmlElement.name == 'dc:creator'],
2> Creat = CreatRec#xmlElement.content,
2> [CreatText] = [X || X <- Creat, is_record(X,xmlText)],
2> Aut = CreatText#xmlText.value.
"Cecelia Ahern"

Can't authenticate using Quickbooks web connector / CFML

I am attempting to implement a Quickbooks Web connector (QBWC) in Railo 4.x
<cfcomponent output="false">
<cffunction name = "authenticate" access="remote" returntype="string">
<cfargument name = "username" type="string" required="true">
<cfargument name = "password" type = "string" required="true">
<cfset var loc = {}>
<cfset loc.retVal= []>
<cfset loc.retVal[1] = "MYSESSIONTOKEN">
<cfset loc.retVal[2] = "NONE">
<cfset loc.retVal[3] = "">
<cfset loc.retVal[4] = "">
<cfreturn loc.retVal >
</cffunction>
<cffunction name = "clientVersion" access="remote" returnType ="string">
<cfargument name = "productVersion" type="string" required="true">
<cfset var loc = {}>
<cfset loc.retVal = "">
<cfreturn loc.retVal>
</cffunction>
</cfcomponent>
This is my QWC file:
<?xml version="1.0"?>
<QBWCXML>
<AppName>QuickCellarSVC</AppName>
<AppID></AppID>
<AppURL>http://localhost:8080/QuickCellar.cfc</AppURL>
<AppDescription>Quick Cellar railo component</AppDescription>
<AppSupport>http://localhost:8080/support.cfm</AppSupport>
<UserName>Joe</UserName>
<OwnerID>{57F3B9B1-86F1-4fcc-B1EE-566DE1813D20}</OwnerID>
<FileID>{90A44FB5-33D9-4815-AC85-BC87A7E7D1EB}</FileID>
<QBType>QBFS</QBType>
<Scheduler>
<RunEveryNMinutes>2</RunEveryNMinutes>
</Scheduler>
</QBWCXML>
The QBWC trace shows the problem :
Object reference not set to an instance of an object.
More info:
StackTrace = at QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)
Source = QBWebConnector
I was able to drill down a little more and discover that there is a casting problem in Railo maybe?
<?xml version="1.0" encoding="UTF-8"?>
-<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">-<soap:Body>-
Can't cast Complex Object Type Struct to StringUse Built-In-Function "serialize(Struct):String" to create a String from Struct
Now I know some of you are thinking "just serialize" the struct. Well, there is no such function in Railo (that I know of).
Any ideas are greatly appreciated.
The first issue I see is your "authenticate" method has return type of string, but you are returning an array. If you are trying to return a string you could use return serializeJSON(loc.retVal) instead of just retVal, which would return it as a JSON formatted string.

xml.parse return null google app script

I am trying parse the xml but result return null.
Here is the xml:
<feed>
<title type="text">neymar</title>
<subtitle type="text">Bing Image Search</subtitle>
<id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$top=2</id>
<rights type="text"/>
<updated>2013-05-13T08:45:02Z</updated>
<link rel="next" href="https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$skip=2&$top=2"/>
<entry>
<id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$skip=0&$top=1</id>
<title type="text">ImageResult</title>
<updated>2013-05-13T08:45:02Z</updated>
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Guid">99cb00e9-c9bb-45ca-9776-1f51e30be398</d:ID>
<d:Title m:type="Edm.String">neymaer wallpaper neymar brazil wonder kid neymar wallpaper hd</d:Title>
<d:MediaUrl m:type="Edm.String">http://3.bp.blogspot.com/-uzJS8HW4j24/Tz3g6bNII_I/AAAAAAAAB1o/ExYxctnybUo/s1600/neymar-wallpaper-5.jpg</d:MediaUrl>
<d:SourceUrl m:type="Edm.String">http://insidefootballworld.blogspot.com/2012/02/neymar-wallpapers.html</d:SourceUrl>
<d:DisplayUrl m:type="Edm.String">insidefootballworld.blogspot.com/2012/02/neymar-wallpapers.html</d:DisplayUrl>
<d:Width m:type="Edm.Int32">1280</d:Width>
<d:Height m:type="Edm.Int32">800</d:Height>
<d:FileSize m:type="Edm.Int64">354173</d:FileSize>
<d:ContentType m:type="Edm.String">image/jpeg</d:ContentType>
<d:Thumbnail m:type="Bing.Thumbnail">
<d:MediaUrl m:type="Edm.String">http://ts3.mm.bing.net/th?id=H.5042206689331494&pid=15.1</d:MediaUrl>
<d:ContentType m:type="Edm.String">image/jpg</d:ContentType>
<d:Width m:type="Edm.Int32">300</d:Width>
<d:Height m:type="Edm.Int32">187</d:Height>
<d:FileSize m:type="Edm.Int64">12990</d:FileSize>
</d:Thumbnail>
</m:properties>
</content>
</entry>
<entry>
<id>https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Query='neymar'&$skip=1&$top=1</id>
<title type="text">ImageResult</title>
<updated>2013-05-13T08:45:02Z</updated>
<content type="application/xml">
<m:properties>
<d:ID m:type="Edm.Guid">9a6b7476-643e-4844-a8da-a4b640a78339</d:ID>
<d:Title m:type="Edm.String">neymar jr 485x272 Neymar Show 2012 Hd</d:Title>
<d:MediaUrl m:type="Edm.String">http://www.sontransferler.com/wp-content/uploads/2012/07/neymar_jr.jpg</d:MediaUrl>
<d:SourceUrl m:type="Edm.String">http://www.sontransferler.com/neymar-show-2012-hd</d:SourceUrl>
<d:DisplayUrl m:type="Edm.String">www.sontransferler.com/neymar-show-2012-hd</d:DisplayUrl>
<d:Width m:type="Edm.Int32">1366</d:Width>
<d:Height m:type="Edm.Int32">768</d:Height>
<d:FileSize m:type="Edm.Int64">59707</d:FileSize>
<d:ContentType m:type="Edm.String">image/jpeg</d:ContentType>
<d:Thumbnail m:type="Bing.Thumbnail">
<d:MediaUrl m:type="Edm.String">http://ts1.mm.bing.net/th?id=H.4796985557255960&pid=15.1</d:MediaUrl>
<d:ContentType m:type="Edm.String">image/jpg</d:ContentType>
<d:Width m:type="Edm.Int32">300</d:Width>
<d:Height m:type="Edm.Int32">168</d:Height>
<d:FileSize m:type="Edm.Int64">4718</d:FileSize>
</d:Thumbnail>
</m:properties>
</content>
</entry>
</feed>
and here is the code:
var response = UrlFetchApp.fetch('https://api.datamarket.azure.com/Bing/Search/Image?Query=%27neymar%27&$top=2',options)
var resp = response.getContentText();
var ggg = Xml.parse(resp,false).getElement().getElement('entry').getElement('content').getElement('m:properties');
Logger.log(ggg);
How do I get element <d:MediaUrl m:type="Edm.String">?
update: but still not work
var response = UrlFetchApp.fetch('https://api.datamarket.azure.com/Bing/Search/Image?Query=%27neymar%27&$top=2',options)
var text = response.getContentText();
var eleCont = Xml.parse(text,true).getElement().getElement('entry').getElement('content');
var eleProp = eleCont.getElement('hxxp://schemas.microsoft.com/ado/2007/08/dataservices/metadata','properties')
var medUrl= eleProp.getElement('hxxp://schemas.microsoft.com/ado/2007/08/dataservices','MediaUrl').getText()
Logger.log(medUrl)
While the provider is using multiple namespaces (signified by m: and d: in front of element names), you can ignore them for retrieving the data you're interested in.
Once you've called getElement() to get the root of the XML doc, you can navigate through the rest using attribute names. (Stop after var feed = ... in the debugger, and explore feed, you'll find you have the entire XML document there
Try this:
var text = Xml.parse(resp,true);
var feed = text.getElement();
var urls = [];
for (var i in feed.entry) {
urls.push(feed.entry[0].content.properties.MediaUrl.Text);
}
Logger.log(urls);
This also works. Note that you have multiple entries in your response, and this example is going after the second of them:
var ggg = Xml.parse(resp,true)
.getElement()
.getElements('entry')[1]
.getElement('content')
.getElement('properties')
.getElement('MediaUrl')
.getText();
References
Namespaces in XML 1.0
XmlElement methods referencing namespace, such as getElement(namespaceName, localName)
Other relevant StackOverflow questions. xml element name with colon, lots about XML namespaces

Resources