@azure/core-xml
Advanced tools
Comparing version 1.1.1-alpha.20220112.1 to 1.2.0-alpha.20220120.2
# Release History | ||
## 1.1.1 (Unreleased) | ||
## 1.2.0 (Unreleased) | ||
### Features Added | ||
### Other Changes | ||
### Breaking Changes | ||
- Upgrade to `fast-xml-parser` to v4 [PR# 19898](https://github.com/Azure/azure-sdk-for-js/pull/19898) | ||
### Bugs Fixed | ||
### Other Changes | ||
## 1.1.0 (2022-01-06) | ||
@@ -14,0 +10,0 @@ |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { j2xParser, parse, validate } from "fast-xml-parser"; | ||
import { XMLBuilder, XMLValidator, XMLParser } from "fast-xml-parser"; | ||
import { XML_ATTRKEY, XML_CHARKEY } from "./xml.common"; | ||
@@ -8,5 +8,6 @@ function getCommonOptions(options) { | ||
return { | ||
attrNodeName: XML_ATTRKEY, | ||
attributesGroupName: XML_ATTRKEY, | ||
textNodeName: (_a = options.xmlCharKey) !== null && _a !== void 0 ? _a : XML_CHARKEY, | ||
ignoreAttributes: false, | ||
suppressBooleanAttributes: false, | ||
}; | ||
@@ -16,6 +17,6 @@ } | ||
var _a; | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { attributeNamePrefix: "@_", format: true, supressEmptyNode: true, indentBy: "", rootNodeName: (_a = options.rootName) !== null && _a !== void 0 ? _a : "root" }); | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { attributeNamePrefix: "@_", format: true, suppressEmptyNode: true, indentBy: "", rootNodeName: (_a = options.rootName) !== null && _a !== void 0 ? _a : "root" }); | ||
} | ||
function getParserOptions(options = {}) { | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { parseAttributeValue: false, parseNodeValue: false, attributeNamePrefix: "" }); | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { parseAttributeValue: false, parseTagValue: false, attributeNamePrefix: "" }); | ||
} | ||
@@ -30,5 +31,5 @@ /** | ||
const parserOptions = getSerializerOptions(opts); | ||
const j2x = new j2xParser(parserOptions); | ||
const j2x = new XMLBuilder(parserOptions); | ||
const node = { [parserOptions.rootNodeName]: obj }; | ||
const xmlData = j2x.parse(node); | ||
const xmlData = j2x.build(node); | ||
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${xmlData}`.replace(/\n/g, ""); | ||
@@ -46,7 +47,8 @@ } | ||
} | ||
const validation = validate(str); | ||
const validation = XMLValidator.validate(str); | ||
if (validation !== true) { | ||
throw validation; | ||
} | ||
const parsedXml = parse(unescapeHTML(str), getParserOptions(opts)); | ||
const parser = new XMLParser(getParserOptions(opts)); | ||
const parsedXml = parser.parse(unescapeHTML(str)); | ||
if (!opts.includeRoot) { | ||
@@ -53,0 +55,0 @@ for (const key of Object.keys(parsedXml)) { |
@@ -22,5 +22,6 @@ 'use strict'; | ||
return { | ||
attrNodeName: XML_ATTRKEY, | ||
attributesGroupName: XML_ATTRKEY, | ||
textNodeName: (_a = options.xmlCharKey) !== null && _a !== void 0 ? _a : XML_CHARKEY, | ||
ignoreAttributes: false, | ||
suppressBooleanAttributes: false, | ||
}; | ||
@@ -30,6 +31,6 @@ } | ||
var _a; | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { attributeNamePrefix: "@_", format: true, supressEmptyNode: true, indentBy: "", rootNodeName: (_a = options.rootName) !== null && _a !== void 0 ? _a : "root" }); | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { attributeNamePrefix: "@_", format: true, suppressEmptyNode: true, indentBy: "", rootNodeName: (_a = options.rootName) !== null && _a !== void 0 ? _a : "root" }); | ||
} | ||
function getParserOptions(options = {}) { | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { parseAttributeValue: false, parseNodeValue: false, attributeNamePrefix: "" }); | ||
return Object.assign(Object.assign({}, getCommonOptions(options)), { parseAttributeValue: false, parseTagValue: false, attributeNamePrefix: "" }); | ||
} | ||
@@ -44,5 +45,5 @@ /** | ||
const parserOptions = getSerializerOptions(opts); | ||
const j2x = new fastXmlParser.j2xParser(parserOptions); | ||
const j2x = new fastXmlParser.XMLBuilder(parserOptions); | ||
const node = { [parserOptions.rootNodeName]: obj }; | ||
const xmlData = j2x.parse(node); | ||
const xmlData = j2x.build(node); | ||
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>${xmlData}`.replace(/\n/g, ""); | ||
@@ -60,7 +61,8 @@ } | ||
} | ||
const validation = fastXmlParser.validate(str); | ||
const validation = fastXmlParser.XMLValidator.validate(str); | ||
if (validation !== true) { | ||
throw validation; | ||
} | ||
const parsedXml = fastXmlParser.parse(unescapeHTML(str), getParserOptions(opts)); | ||
const parser = new fastXmlParser.XMLParser(getParserOptions(opts)); | ||
const parsedXml = parser.parse(unescapeHTML(str)); | ||
if (!opts.includeRoot) { | ||
@@ -67,0 +69,0 @@ for (const key of Object.keys(parsedXml)) { |
{ | ||
"name": "@azure/core-xml", | ||
"version": "1.1.1-alpha.20220112.1", | ||
"version": "1.2.0-alpha.20220120.2", | ||
"description": "Core library for interacting with XML payloads", | ||
@@ -69,3 +69,3 @@ "sdk-type": "client", | ||
"tslib": "^2.2.0", | ||
"fast-xml-parser": "^3.20.0" | ||
"fast-xml-parser": "^4.0.1" | ||
}, | ||
@@ -72,0 +72,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46458
414
+ Addedfast-xml-parser@4.5.1(transitive)
- Removedfast-xml-parser@3.21.1(transitive)
Updatedfast-xml-parser@^4.0.1