How to decode xml content using webread ?

22 ビュー (過去 30 日間)
Marc Youcef
Marc Youcef 2019 年 7 月 15 日
編集済み: Andrew Black 2021 年 6 月 16 日
Hello,
I am doing a webread that gives an xml document :
url='***'; % not displayed
data = webread(url)
My issue is that I am getting characters like :
"<?xml version="1.0" encoding="UTF-8"?&gt"
It is clear that the xml data is not decoded correctly. I have tried to use weboptions by specifying 'MediaType' and 'ContentType' but it did not help at all :
options = weboptions(...
'MediaType','text/xml');
The above changed nothing.
options = weboptions(...
'ContentType', 'xmldom')
The above retreived no data at all.
The xml document is embedded into an soap Envelope liek this :
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:***>
<TheXMLIwant>
<?xml version="1.0" encoding="UTF-8"?>
<blabla>123456</blabla>
</TheXMLIwant>
</ns2:***>
</soap:Body>
</soap:Envelope>
I found a function from MATLAB doing what I need but you have to have a Text Analytics toolbox which I guess is completely overshoot fo what is required here:
Should be a way to do this with the webread.
Thanks in advance.

回答 (1 件)

Andrew Black
Andrew Black 2021 年 6 月 16 日
編集済み: Andrew Black 2021 年 6 月 16 日
I encountered this same problem, and there's a bit of a workaround described here:
and the xmldom structure described nicely here:
Once you have xmlreadstring.m from the first link in your path:
wr = webread(url);
dom = xmlreadstring(wr);
and your XML data, from your url is now in dom.
I am not sure how the soap envelope will effect this, but if you strip the envelope from your xml string, it should work.

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by