How to use the fast-xml-parser.parse function in fast-xml-parser

To help you get started, we’ve selected a few fast-xml-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github magda-io / magda / magda-web-client / src / helpers / xmlToTabular.ts View on Github external
export default function(xmlData: string) {
    // when a tag has attributes
    const options = {
        attrPrefix: "@_",
        textNodeName: "#text",
        ignoreNonTextNodeAttr: true,
        ignoreTextNodeAttr: true,
        ignoreNameSpace: true,
        ignoreRootElement: false,
        textNodeConversion: true,
        textAttrConversion: false
    };
    if (fastXmlParser.validate(xmlData) === true) {
        //optional
        const jsonObj = fastXmlParser.parse(xmlData, options);
        var array = jsonToArray(jsonObj);
        const data = {
            data: array,
            meta: {
                fields: ["name", "value"],
                type: "tabular"
            }
        };
        return data;
    }
    return null;
}
github jimmykane / quantified-self-lib / src / events / adapters / importers / suunto / importer.suunto.sml.ts View on Github external
static getFromXML(contents: string, name = 'New Event'): Promise {
    const json = parser.parse(contents).sml;

    // debugger;

    //  A few mods here to convert it to compatible json suunto string
    json.DeviceLog.Samples = json.DeviceLog.Samples.Sample;

    const samplesWithUTC: any[]  =  json.DeviceLog.Samples.filter((sample: any) => !!sample.UTC);

    // Find the first UTC timestamped sample and use it later for start date
    const startDate = samplesWithUTC.length ? new Date(samplesWithUTC[0].UTC) : new Date(json.DeviceLog.Header.DateTime);


    // Determine the end date
    const endDate = samplesWithUTC.length > 1 ? samplesWithUTC[samplesWithUTC.length - 1].UTC : (new Date((startDate.getTime() + json.DeviceLog.Header.Duration * 1000)));

    // Filter out the old activity type
github DrewML / scd / src / magentoFS.ts View on Github external
async function getModuleConfig(root: string, path: string): Promise {
    const configPath = join(root, path, 'etc', 'module.xml');
    const rawConfig = await fs.readFile(configPath, 'utf8');
    const parsedConfig = parse(rawConfig, {
        ignoreAttributes: false,
        attributeNamePrefix: '',
        ignoreNameSpace: true,
    });

    const config = {
        moduleID: parsedConfig.config.module.name as string,
        sequence: [] as string[],
        pathFromStoreRoot: join(sep, path),
    };
    const { sequence } = parsedConfig.config.module;

    if (!sequence) return config;

    if (Array.isArray(sequence.module)) {
        // multiple dependencies
github lmmfranco / nintendo-switch-eshop / src / nintendo-switch-eshop.ts View on Github external
export const getGamesJapan = async (): Promise => {
  try {
    const gamesJP = await fetch(constants.JP_GET_GAMES_URL);

    if (!gamesJP.ok) throw new Error('JP_games_request_failed');

    const parsedGamesJP = xml2json(await gamesJP.text());

    const allGamesJP: interfaces.GameJP[] = parsedGamesJP.TitleInfoList.TitleInfo;

    return allGamesJP;
  } catch (err) {
    if (/(?:JP_games_request_failed)/i.test(err.toString())) throw new constants.EshopError('Fetching of JP Games failed');
    throw err;
  }
};
github creditsenseau / zeebe-client-node-js / dist / lib / BpmnParser.js View on Github external
static getProcessId(bpmnString) {
        const jsonObj = parser.parse(bpmnString, BpmnParser.parserOptions);
        if (jsonObj) {
            if (jsonObj["bpmn:definitions"]) {
                if (jsonObj["bpmn:definitions"]["bpmn:process"]) {
                    const attr = jsonObj["bpmn:definitions"]["bpmn:process"].attr;
                    return attr ? attr["@_id"] : undefined;
                }
            }
        }
        return undefined;
    }
    /**
github recca0120 / vscode-phpunit / src / parsers / junit.ts View on Github external
return new Promise((resolve, reject) => {
            resolve(
                require('fast-xml-parser').parse(content, {
                    attrPrefix: '_',
                    textNodeName: '__',
                    ignoreNonTextNodeAttr: false,
                    ignoreTextNodeAttr: false,
                    ignoreNameSpace: false,
                })
            );
        });
    }
github fabiospampinato / enex-dump / src / parse.js View on Github external
async xml ( filePath ) {

    const content = await File.read ( filePath );

    try {

      return xml2js ( content );

    } catch ( e ) {}

  }
github karimomaya / OTCL / engine / __OTPostRequest.js View on Github external
function cleanXML(message){
        var fastXmlParser = require('fast-xml-parser');
		var jsonObj = fastXmlParser.parse(message);
		return jsonObj;
    }
github marcellourbani / abap-adt-api / src / api / transports.ts View on Github external
export async function systemUsers(h: AdtHTTP) {
  const response = await h.request("/sap/bc/adt/system/users", {
    headers: { Accept: "application/*" }
  })
  const raw = parse(response.body)
  return xmlArray(raw, "atom:feed", "atom:entry").map(
    (r: any): SystemUser => ({ id: r["atom:id"], title: r["atom:title"] })
  )
}
github vmware / vrealize-developer-tools / extension / src / client / lint / rule / ToolchainVersionRule.ts View on Github external
private extractParentVersion(pomXmlContent: string): string | null {
        const pomXml = xmlParser.parse(pomXmlContent)

        if (!pomXml.project || !pomXml.project.parent) {
            this.logger.warn("Missing parent tag")
            return null
        }

        const groupId: string = pomXml.project.parent.groupId
        const artifactId: string = pomXml.project.parent.artifactId
        const version: string = pomXml.project.parent.version

        if (!groupId || !artifactId) {
            this.logger.warn(`Missing groupId or artifactId - ${groupId}.${artifactId}`)
            return null
        }

        if (PomFile.ParentGroupByArtifact[artifactId] !== groupId) {

fast-xml-parser

Validate XML, Parse XML, Build XML without C/C++ based libraries

MIT
Latest version published 2 months ago

Package Health Score

91 / 100
Full package analysis