mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-22 15:39:31 +02:00
feat(xml): add XML tools for validation, beautification, and viewing
This commit is contained in:
16
src/pages/tools/xml/xml-validator/service.ts
Normal file
16
src/pages/tools/xml/xml-validator/service.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { InitialValuesType } from './types';
|
||||
import { XMLValidator } from 'fast-xml-parser';
|
||||
|
||||
export function validateXml(
|
||||
input: string,
|
||||
_options: InitialValuesType
|
||||
): string {
|
||||
const result = XMLValidator.validate(input);
|
||||
if (result === true) {
|
||||
return 'Valid XML';
|
||||
} else if (typeof result === 'object' && result.err) {
|
||||
return `Invalid XML: ${result.err.msg} (line ${result.err.line}, col ${result.err.col})`;
|
||||
} else {
|
||||
return 'Invalid XML: Unknown error';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user