Javascript/라이브러리 및 API

xml-parser를 위한 fast-xml-parser 라이브러리

Dev갱이 2024. 7. 14. 16:07
728x90

어이가없군

 

공공데이터포털에서 제공하는 Api를 호출 했을때 굉장히 불편함을 느끼는것이 2가지가 있다.
1. 분명히 http 통신인데 성공일때든 실패일때든 http Status 200으로 성공으로 무조건 보내준다.
2. 실패 했을때 status 200으로 성공 상태로 에러 주는것도 불편한데 심지어 xml로 준다.

 

핸들링 가능한 모든 에러는 다 map으로 이동 된다. catchError는 http request error가 아닌 요청 자체를 못보내는 케이스나 그럴때나 핸들링 가능할것 같다. 예를들면 틀린 url에 요청을 보냈거나 했을때 즉 httpService에러일때나 catchError를 사용될것이다.

 

https://www.npmjs.com/package/fast-xml-parser

 

fast-xml-parser

Validate XML, Parse XML, Build XML without C/C++ based libraries. Latest version: 4.4.0, last published: 2 months ago. Start using fast-xml-parser in your project by running `npm i fast-xml-parser`. There are 2531 other projects in the npm registry using f

www.npmjs.com

 

각설하고 어쩔수없이 에러 상황인경우 xml을 json으로 변환 해주기 위해 해당 라이브러리를 찾았다.
Typescript로 작성 되었고 최근까지 릴리즈 되었다.

 

 

xml을 파싱하여 json으로 변환 해준다!

 

 

자세한 옵션들은 문서를 참고 하면 좋다.

https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md

 

fast-xml-parser/docs/v4/2.XMLparseOptions.md at master · NaturalIntelligence/fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback. - NaturalIntelligence/fast-xml-parser

github.com

 

728x90