Comments (7)
@savvasmarkstatkus APIs are changed in v4.
Eg
const {XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser');
if(XMLValidator.validate()){
const parser = new XMLParser();
let jsonObj = parser.parse(xmlData);
const builder = new XMLBuilder();
let samleXmlData = builder.build(jsonObj);
}
from fast-xml-parser.
- Are you facing problem when you include
fast-xml-parser
or when you use it in your code? - When you are importing other packages why are you using
require
to importfast-xml-parser
?
I believe the problem is more related to syntax not the library. So please change it to import parser from fast-xml-parser
and then try.
from fast-xml-parser.
Could you please provide me an exact syntax? Everything I try did not work
some errors
scripts.bundle.js:1 Uncaught ReferenceError: require is not defined
at scripts.bundle.js:1
(anonymous) @ scripts.bundle.js:1
core.js:3675 Angular is running in the development mode. Call enableProdMode() to enable the production mode.
i-hub-header.component.ts:21 onDashboardClicked(..) executed.
core.js:1440 ERROR TypeError: Cannot read property 'parse' of undefined
at FileReader.reader.onloadend (imp-exp.service.ts:33)
at ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:4733)
at ZoneDelegate.invoke (zone.js:387)
at Zone.runGuarded (zone.js:151)
at FileReader.eval (zone.js:129)
.....
My source code
`
import { Injectable } from '@angular/core';
//var fastXmlParser = require('fast-xml-parser');
import parser from 'fast-xml-parser';
//import { parser } from 'fast-xml-parser';
@Injectable()
export class ImpExpService {
private files: any;
private fileContent: any;
constructor() {
}
setLoadedFiles(loadedFiles: any) {
this.files = loadedFiles;
const reader = new FileReader();
for (let item of this.files) {
reader.readAsText(item, 'utf8');
var that = this;
reader.onloadend = function () {
that.fileContent = reader.result;
debugger;
var jsonObj = parser.parse(that.fileContent);
debugger;
}
}
}
}
`
from fast-xml-parser.
I believe the issue is related to ES6 implementation. Check https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c
Have you tried to import any other 3rd party library?
from fast-xml-parser.
Hi,
I found a solution, just add the line "declare var require: any;" before the require.
Regards Jürgen
import { Injectable } from '@angular/core';
import { ImportData } from 'thevoidmodelmodule/dist/shared';
import { SBKDispoListen, SBKOrder } from 'thevoidmodelmodule/dist/ihub';
import { MongoDBService } from '../mongo-db.service';
declare var require: any;
var fastXmlParser = require('fast-xml-parser');
@Injectable()
export class ImpExpService {
private files: any;
private fileContent: any;
private sbkDispoListen: SBKDispoListen = null;
constructor(private mongoDBService: MongoDBService) {
}
....
}
from fast-xml-parser.
I had better luck just using v3.19.0 vs 4 in Angular. Didn't want to spend anymore time dealing with TS errors.
"fast-xml-parser": "^3.19.0",
import { parse } from "fast-xml-parser"; // Couldn't get v4 to work, v3 seemed to.
this.result = parse(xmlStr, options);
from fast-xml-parser.
With Angular 13 I was getting Type 'XMLParser' has no call signatures. I tweaked it based on your example and looks like I was missing the parser.parse
. Thanks.
from fast-xml-parser.
Related Issues (20)
- Parsing an invalid XML element
- isArray behavior on missing/empty tags HOT 1
- TypeError: Cannot read properties of undefined (reading 'tagName') when parsing closing tag without an opening tag at the start of XML document HOT 3
- V3 to V4 migration guide? HOT 5
- Circular Dependency Error While trying to validate xml HOT 3
- Online demo does not handle DOCTYPE correctly and gives an error HOT 2
- Regex Injection Via Doctype Entities HOT 4
- unreliable for parsing html HOT 2
- Introduce isObject option for unpaired tags HOT 2
- Parsing of Empty Tags HOT 4
- Entities are being processed in CDATA sections HOT 1
- Attribute in oneListGroup is not parsed correctly HOT 1
- All special characters are not correctly parsed HOT 4
- Ability to read & write DOCTYPE information HOT 2
- parser malfunctions when textNodeName is the same as a tag name HOT 8
- Node attributes get lost on XML parsing HOT 1
- Decimal point is not preserved after parsed to json. HOT 6
- Difficulty treating some numeric tags as string HOT 2
- XML parse looks good on Online tool, but when using API crashes HOT 2
- Any tag which has a format like <!D%s> where %s - any sequence of characters is perceived as <!DOCTYPE> and causes error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-xml-parser.