K
K
kipyatokk2021-12-15 12:45:22
JavaScript
kipyatokk, 2021-12-15 12:45:22

I accept xml in a post request with Cyrillic. How to decode content in utf-8 to get correct data?

Purpose: A web service that accepts a post request with xml in the body and performs some actions with it. Encoding win-1251 and Cyrillic in the content naturally.
The example I'm working with

const express = require('express');
const xmlparser = require('express-xml-bodyparser');
const app = express();
const iconv = require('iconv-lite');

app.post('/down', function(req, res){
const buf = req.rawBody;
const str = iconv.decode(buf, 'windows-1251');  
res.send(str);
});

express-xml-bodyparser - helps me see the xml content in req.body and req.rawBody, without it I get an empty body. But instead of Cyrillic I see ������������. Well, there is a wonderful iconv library, I decode the result and business, I thought. But at the output I get eeeeeeeeee ... just a set of Russian characters eeeeee. Please tell me what I missed? The server expects utf-8 encoding and converts the received xml data into it itself. Can I somehow force not to do this, and accept the request in the original encoding.? Or how can I correctly decode the data in order to get the "human" content of the request?
An example xml that I get from a post request.
<?xml version="1.0 encoding="windows-1251"? >
<КоммерческаяИнформация ВидДанных="1">
  <Информация Владелец="123 ДатаВыгрузки="123" ВремяВыгрузки="123" ТипПрайса="123">
    <Номенклатура КодНоменклатуры="123" Номенклатура="Тестовый товар">
      <Предложение Цена="123" СрокГодности="2025-10-01" Остаток="9000" МинЗаказ="" Кратность="250"/>
      <Предложение Цена="123" СрокГодности="2025-09-01" Остаток="4270" МинЗаказ="" Кратность="250"/>
      <Предложение Цена="123" СрокГодности="2025-09-01" Остаток="25500" МинЗаказ="" Кратность="250"/>
      <Предложение Цена="123" СрокГодности="2025-09-01" Остаток="21000" МинЗаказ="" Кратность="250"/>
      <Предложение Цена="123" СрокГодности="2025-09-01" Остаток="10939" МинЗаказ="" Кратность="250"/>
    </Номенклатура>
  </Информация>
</КоммерческаяИнформация>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aigelov, 2015-07-10
@dearname

As an option:

.all_pr li {
  float: left;
  margin: 5px 10px;
  position: relative;
}

var drop_down = $('.demo .drop-down');
  
if ( drop_down.length > 1 )
{
  drop_down.on('click', function()
  {
    $('.all_pr > li').css(
      {
        'z-index' : 0
      }
    );
    $(this).parent().parent().closest('li').css(
      {
        'z-index' : 1
      }
    );
  });
}

Try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question