Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract a QString from xml tag

I have this resulted QString from an http request, What I need to do is to extract only the string "一致" which is inside the tag

"TranslatedText>一致</TranslatedText>"

How to do this?

  <GetTranslationsResponse xmlns="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<From>en</From>
<Translations>
    <TranslationMatch>
        <Count>0</Count>
        <MatchDegree>100</MatchDegree>
        <MatchedOriginalText/>
        <Rating>5</Rating>
        <TranslatedText>一致</TranslatedText>
    </TranslationMatch>
</Translations>

like image 354
Wazery Avatar asked Jan 26 '26 14:01

Wazery


1 Answers

You would use a XPath query to do this.

Use the path:

/GetTranslationsResponse/Translations/TranslationMatch/TranslatedText/text()

To extract the value.

I'm not sure what platform/laguage you're using, so just investigate if QT has XPath support there.

like image 106
monksy Avatar answered Jan 28 '26 08:01

monksy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!