Get xml data from web into Matlab struct using webread and readstruct
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Faisal
el 4 de Oct. de 2024
Respondida: Animesh
el 4 de Oct. de 2024
I have been getting data from a web API, which returns the data in xml format. I can parse this into a Matlab struct, but only by first saving the char array to a file and then reading it with readstruct.
The below works, but is there any way to do this without writing and reading a file unnecessarily? Either by passing the char array to readstruct or having webread output a struct directly (like it does when the web response is json)?
webresponse = webread(url, queryname, queryvalue);
name1 = [tempname(),'.xml'];
writelines(webresponse, name1);
out = readstruct(name1);
0 comentarios
Respuesta aceptada
Animesh
el 4 de Oct. de 2024
To import XML data directly into a struct, you can use the "xml2struct" function, which is available on the MATLAB File Exchange. Here's how you can do it:
% Make sure that xml2struct is in your path
webresponse = webread(url, queryname, queryvalue);
out = xml2struct(webresponse);
Here is the link to the File Exchange page for "xml2struct":
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!