Google Sheets – ImportXML Strips Leading Zeros Solution

google sheetsimportxml

I extract one number from an XML online file with Google Spreadsheets. Sometimes the number starts with a zero but the spreadsheet removes it. I'm sure the format of the cell is 'plain text' (I press 020 and 020 appears), but after entering the formula it's like if it became 'number'.

Assuming this data XML:

<sudoc service="ean2ppn">
<query>
<ean>9782870098585</ean>
<result>
<ppn>080253431</ppn>
</result>
</query>
</sudoc>

Using a formula such as:

=IMPORTXML("http://www.sudoc.fr/services/ean2ppn/9782870098585","/sudoc/query/result/ppn")  

will return 80253431 whereas I would like it to return 080253431. How might I achieve this?

Best Answer

With the formula TEXT(number, format) we can force the display of zeros.

In my case the formula is now: =TEXT(IMPORTXML(linkOfData,xpath), "000000000")