NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.43k stars 297 forks source link

parser malfunctions when textNodeName is the same as a tag name #640

Closed ledlamp closed 4 months ago

ledlamp commented 4 months ago

Description

### Input

Code

var {XMLParser} = require("fast-xml-parser")

var parser = new XMLParser({
    ignoreAttributes: false,
    textNodeName: "text",
    attributeNamePrefix: ""
});

var xml = await fetch("https://www.youtube.com/api/timedtext?v=NXpdyAWLDas&ei=gRHRZZC4Md_bsfIPsNSSiAk&caps=asr&opi=112496729&xoaf=5&hl=en&ip=0.0.0.0&ipbits=0&expire=1708225521&sparams=ip,ipbits,expire,v,ei,caps,opi,xoaf&signature=9245C4DAB6A53D42237FCD8458982918C0AAF73B.E4859B1969EF13186C9810146EDE8837B3DE9B3B&key=yt8&lang=en").then(res => res.text());

console.log(JSON.stringify(parser.parse(xml)));

Output

{"?xml":{"version":"1.0","encoding":"utf-8"},"transcript":"[object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object]"}

expected data

{"?xml":{"version":"1.0","encoding":"utf-8"},"transcript":{"text":[{"text":"- [Will] That's hot.\n(bright upbeat music)","start":"0","dur":"2.233"},{"text":"- All right, so this is\nsimultaneously really impressive","start":"2.233","dur":"4.847"},{"text":"and really frightening at the same time,","start":"7.08","dur":"3.66"},{"text":"and it's hitting me in ways\nthat I didn't really expect.","start":"10.74","dur":"1.95"},{"text":"So do you remember Will\nSmith eating spaghetti?","start":"12.69","dur":"2.49"},{"text":"Do you remember when this","start":"15.18","dur":"1.14"},{"text":"was what AI generated videos looked like?","start":"16.32","dur":"2.07"},{"text":"Remember when we said, "Okay,\nthis AI stuff is cool and all","start":"18.39","dur":"2.557"},{"text":""but clearly there's a long way to go","start":"20.947","dur":"2.04"},{"text":""before there's any need for concern."","start":"22.987","dur":"2.633"},{"text":"Well, welcome to the future people","start":"25.62","dur":"1.89"},{"text":"because this is also\nan AI generated video.","start":"27.51","dur":"4.59"},{"text":"And so is this, completely\nsynthesized out of thin air","start":"32.1","dur":"3.03"},{"text":"by computers.","start":"35.13","dur":"1.32"},{"text":"This one too, this is not real.","start":"36.45","dur":"2.88"},{"text":"Absolutely ridiculous","start":"39.33","dur":"1.23"},{"text":"how far we've come in literally one year.","start":"40.56","dur":"2.82"},{"text":"This does feel like another\nChatGPT, DALL.E moment for AI.","start":"43.38","dur":"5"},{"text":"And maybe I'm overreacting","start":"49.41","dur":"1.14"},{"text":"because, okay, I am a video creator,","start":"50.55","dur":"2.76"},{"text":"so an AI that's actually doing my job,","start":"53.31","dur":"3.15"},{"text":"maybe that feels a little more threatening","start":"56.46","dur":"1.59"},{"text":"so I'm particularly impressed by it.","start":"58.05","dur":"1.53"},{"text":"But also this stuff is really good.","start":"59.58","dur":"2.73"},{"text":"So today, Sam Altman and\nOpenAI announced a new model","start":"62.31","dur":"3.96"},{"text":"called Sora and it can generate","start":"66.27","dur":"2.25"},{"text":"full up to one minute video\nclips from just text input.","start":"68.52","dur":"4.62"},{"text":"So the same way DALL.E was able\nto understand our text input","start":"73.14","dur":"4.2"},{"text":"and turn it into a photorealistic","start":"77.34","dur":"2.34"},{"text":"or stylized image or whatever you want,","start":"79.68","dur":"2.37"},{"text":"same thing with Sora but\nnow since it's videos,","start":"82.05","dur":"3.72"},{"text":"it also needs to understand","start":"85.77","dur":"2.34"},{"text":"how all these things like\nreflections and textures","start":"88.11","dur":"3.24"},{"text":"and materials and physics\nall interact with each other","start":"91.35","dur":"3.9"},{"text":"over time to make a\nreasonable looking video.","start":"95.25","dur":"2.52"},{"text":"And of course, right away,\nthere's a bunch of examples","start":"97.77","dur":"2.1"},{"text":"on their website that are crazy.","start":"99.87","dur":"1.32"},{"text":"Now, before I show you these,","start":"101.19","dur":"1.17"},{"text":"I just need you to keep this in mind,","start":"102.36","dur":"1.65"},{"text":"you're about to watch a\nbunch of AI generated videos","start":"104.01","dur":"3.36"},{"text":"and you know that you're about to watch","start":"107.37","dur":"2.58"},{"text":"a bunch of AI generated content.","start":"109.95","dur":"1.41"},{"text":"So your brain, you're already\nlooking for this stuff","start":"111.36","dur":"2.58"},{"text":"and it's not perfect, you\nwill find imperfections,","start":"113.94","dur":"3.18"},{"text":"but not everybody who\nsees AI generated content","start":"117.12","dur":"3.54"},{"text":"on the internet knows\nto be looking for that.","start":"120.66","dur":"3.42"},{"text":"So also keep that in mind.","start":"124.08","dur":"2.19"},{"text":"This is also the worst\nthat this technology","start":"126.27","dur":"2.22"},{"text":"is going to be from here on out.","start":"128.49","dur":"1.98"},{"text":"So, okay, here's one of the videos.","start":"130.47","dur":"1.59"},{"text":"There's no audio to any of these clips,","start":"132.06","dur":"1.68"},{"text":"but the prompt for this one","start":"133.74","dur":"1.5"},{"text":"is a stylish woman walks\ndown a Tokyo street","start":"135.24","dur":"3.39"},{"text":"filled with warm, glowing,\nneon and animated city signage.","start":"138.63","dur":"3.48"},{"text":"She wears a black leather jacket,","start":"142.11","dur":"1.8"},{"text":"a long red dress and black boots.","start":"143.91","dur":"2.91"},{"text":"This video is already miles\nahead of where we were.","start":"146.82","dur":"4.14"},{"text":"It has accurate lighting,\nit has materials,","start":"150.96","dur":"2.82"},{"text":"it has skin tones, movements,","start":"153.78","dur":"2.4"},{"text":"even has reflections all over the place.","start":"156.18","dur":"2.58"},{"text":"Now, of course, if you look at it","start":"158.76","dur":"1.23"},{"text":"for more than about 10\nseconds, very closely,","start":"159.99","dur":"2.49"},{"text":"there are lots of giveaways.","start":"162.48","dur":"1.38"},{"text":"Like this dude in the background","start":"163.86","dur":"1.26"},{"text":"kinda looks like he's\ngliding in a weird way.","start":"165.12","dur":"3.21"},{"text":"The frame rates and the\nreflections in the water","start":"168.33","dur":"1.8"},{"text":"are for some reason lower\nthan the rest of the video.","start":"170.13","dur":"2.61"},{"text":"The camera movement overall\nis just a bit inconsistent","start":"172.74","dur":"2.16"},{"text":"and it just, I don't know,","start":"174.9","dur":"1.2"},{"text":"it just kinda feels a little bit off.","start":"176.1","dur":"2.7"},{"text":"But then again, this is\nwhere we were one year ago.","start":"178.8","dur":"3.87"},{"text":"So just keep that in the back\nof your head for all this.","start":"182.67","dur":"2.94"},{"text":"Okay, how about this one?","start":"185.61","dur":"0.833"},{"text":"This is another one\nwhich has a long prompt","start":"186.443","dur":"2.497"},{"text":"about a camera following\nbehind a white vintage SUV","start":"188.94","dur":"3.39"},{"text":"with a black roof rack as it's\nspeeds up a steep dirt road.","start":"192.33","dur":"4.32"},{"text":"This is also, again, really good.","start":"196.65","dur":"3.48"},{"text":"It kinda looks a little more video gamey","start":"200.13","dur":"1.77"},{"text":"because of how rock solid\nthe drone footage is,","start":"201.9","dur":"2.85"},{"text":"but clearly very usable.","start":"204.75","dur":"2.4"},{"text":"Here's another one,","start":"207.15","dur":"0.93"},{"text":"a litter of golden retriever\npuppies playing in the snow.","start":"208.08","dur":"3.27"},{"text":"Their heads pop in and out\nof the snow covered in it,","start":"211.35","dur":"3.15"},{"text":"it's so good.","start":"214.5","dur":"0.833"},{"text":"It feels like the physics\nof the fur and the ears","start":"215.333","dur":"2.467"},{"text":"and everything with the snow\nflying around in slow motion","start":"217.8","dur":"3.63"},{"text":"is incredible.","start":"221.43","dur":"0.833"},{"text":"I've looked through all\nof the sample videos","start":"222.263","dur":"1.537"},{"text":"on OpenAI's website,","start":"223.8","dur":"1.26"},{"text":"and clearly these are\nthe handpicked best ones","start":"225.06","dur":"2.94"},{"text":"that they chose to share","start":"228","dur":"1.17"},{"text":"where they just put in some text","start":"229.17","dur":"1.5"},{"text":"and then get a video and don't modify it.","start":"230.67","dur":"2.25"},{"text":"But there's really\nimpressive stuff in there.","start":"232.92","dur":"1.32"},{"text":"Some of it has humans, some of it doesn't.","start":"234.24","dur":"1.83"},{"text":"Some of it is more realistic feeling","start":"236.07","dur":"2.22"},{"text":"like the truck driving one,","start":"238.29","dur":"1.17"},{"text":"but some of them are more\nvideo gamey or more stylized.","start":"239.46","dur":"3.39"},{"text":"A lot of it is slow motion,","start":"242.85","dur":"1.14"},{"text":"I just have to say how insanely fast","start":"243.99","dur":"2.64"},{"text":"these models are improving is genuinely,","start":"246.63","dur":"3.36"},{"text":"like that's the shocking part.","start":"249.99","dur":"1.35"},{"text":"Like I remember not even that\nmany months ago, DALL-E 3,","start":"251.34","dur":"3.66"},{"text":"really, really high end,","start":"255","dur":"1.68"},{"text":"and you could always still\nfind something off about it.","start":"256.68","dur":"2.76"},{"text":"Like especially if you ask it","start":"259.44","dur":"1.26"},{"text":"for something like a\nphotorealistic image of a human,","start":"260.7","dur":"4.65"},{"text":"something about like the hands or the ears","start":"265.35","dur":"2.97"},{"text":"would always just be a little bit off,","start":"268.32","dur":"2.13"},{"text":"nevermind the physics.","start":"270.45","dur":"1.02"},{"text":"But even this video here\nis crazy at first glance.","start":"271.47","dur":"4.56"},{"text":"The prompt for this AI generated video","start":"276.03","dur":"1.77"},{"text":"is a young man in his 20s","start":"277.8","dur":"1.92"},{"text":"is sitting on a piece of a\ncloud in the sky reading a book.","start":"279.72","dur":"3.66"},{"text":"This one feels like 90%\nof the way there for me.","start":"283.38","dur":"4.56"},{"text":"Like it's beyond the uncanny valley","start":"287.94","dur":"1.89"},{"text":"of like apple's personas,","start":"289.83","dur":"1.47"},{"text":"which are actually based on humans.","start":"291.3","dur":"2.04"},{"text":"This is a made up person.","start":"293.34","dur":"1.59"},{"text":"I mean, his eyes are kinda weird,","start":"294.93","dur":"1.38"},{"text":"and the motion of the pages\nin the book are kinda odd.","start":"296.31","dur":"3.18"},{"text":"And yeah, obviously, he's in\na cloud and that's a giveaway","start":"299.49","dur":"1.912"},{"text":"but like, the lighting and\nthe shadows and the skin tones","start":"301.402","dur":"4.058"},{"text":"and then all the realism of\nthe textures on the shirt","start":"305.46","dur":"2.13"},{"text":"and the way the shirt and\nthe pants move and the hair,","start":"307.59","dur":"2.34"},{"text":"they're all really impressive.","start":"309.93","dur":"1.86"},{"text":"And then for this one,","start":"311.79","dur":"0.99"},{"text":"they typed in a movie trailer","start":"312.78","dur":"2.31"},{"text":"featuring the adventurers\nof the 30-year old spaceman","start":"315.09","dur":"3.99"},{"text":"wearing a red wool knitted\nmotorcycle helmet, blue sky,","start":"319.08","dur":"4.11"},{"text":"salt desert, cinematic style,\nshot on 35 millimeter film.","start":"323.19","dur":"5"},{"text":"And the closeups of his face,\nthe fabrics on the helmet,","start":"328.47","dur":"4.62"},{"text":"the film grain through every\nshot and the cinematic style,","start":"333.09","dur":"3.3"},{"text":"this is one of the most\nconvincing AI generated videos","start":"336.39","dur":"3.87"},{"text":"I've ever seen, minus\nmaybe the weird physics","start":"340.26","dur":"2.73"},{"text":"of that dude walking\nkind of in fast motion.","start":"342.99","dur":"2.25"},{"text":"So Sam Altman, if you\nfollow him on Twitter,","start":"345.24","dur":"1.59"},{"text":"he's going through a whole bunch more","start":"346.83","dur":"1.08"},{"text":"of like people's requests","start":"347.91","dur":"1.83"},{"text":"and posting a bunch more generated videos.","start":"349.74","dur":"2.1"},{"text":"And so if you wanna check out his profile,","start":"351.84","dur":"1.23"},{"text":"you can see those.","start":"353.07","dur":"0.833"},{"text":"But here's the thing about\nthese AI generated videos now,","start":"353.903","dur":"4.627"},{"text":"as good as they've gotten to this point,","start":"358.53","dur":"2"},{"text":"they can and will pass as real videos","start":"361.38","dur":"5"},{"text":"to people who are not looking\nfor AI generated videos.","start":"366.51","dur":"3.39"},{"text":"Now that is obviously insanely sketchy","start":"369.9","dur":"3.24"},{"text":"during an election year in the U.S.","start":"373.14","dur":"1.74"},{"text":"and also terrifying","start":"374.88","dur":"0.9"},{"text":"for a bunch of other\ninternet related reasons","start":"375.78","dur":"2.07"},{"text":"but it's also perfect for stock footage.","start":"377.85","dur":"4.44"},{"text":"Like there are already\nall kinds of presentations","start":"382.29","dur":"3.39"},{"text":"and advertisements and then PowerPoints","start":"385.68","dur":"2.76"},{"text":"that are in need of oddly\nspecific stock videos.","start":"388.44","dur":"4.65"},{"text":"And these AI generated videos\nare already good enough","start":"393.09","dur":"4.95"},{"text":"to 100% pass for that purpose.","start":"398.04","dur":"2.79"},{"text":"Like look at this one,\nthis one with the waves","start":"400.83","dur":"2.1"},{"text":"at Big Sur, this drone shot.","start":"402.93","dur":"2.49"},{"text":"Honestly, if I saw this on Twitter,","start":"405.42","dur":"2.4"},{"text":"I wouldn't even think twice.","start":"407.82","dur":"1.11"},{"text":"I'd be like, "Oh, nice drone shot, dude."","start":"408.93","dur":"1.86"},{"text":"Wouldn't even think about\nAI if I wasn't pixel peeping","start":"410.79","dur":"2.88"},{"text":"at like the way the water was moving.","start":"413.67","dur":"1.89"},{"text":"Like this is a totally\nusable video in an ad","start":"415.56","dur":"3.45"},{"text":"for some California based product.","start":"419.01","dur":"2.07"},{"text":"And that has all sorts of\nimplications for the drone pilot","start":"421.08","dur":"4.02"},{"text":"that no longer needs to be hired,","start":"425.1","dur":"2.1"},{"text":"for all the photographers\nand videographers","start":"427.2","dur":"2.43"},{"text":"whose footage no longer\nneeds to be licensed","start":"429.63","dur":"2.94"},{"text":"to show up in that ad that's being made.","start":"432.57","dur":"2.4"},{"text":"It's already that good.","start":"434.97","dur":"1.68"},{"text":"There's other stuff like this wall of TVs,","start":"436.65","dur":"2.4"},{"text":"which would be a totally\nexpensive and difficult thing","start":"439.05","dur":"2.79"},{"text":"to shoot with a camera and\nall these old expensive props,","start":"441.84","dur":"3.48"},{"text":"but if you can just generate\nit this well with reflections","start":"445.32","dur":"4.2"},{"text":"and the environment and\neverything else around it,","start":"449.52","dur":"2.61"},{"text":"I mean, why do it any other way?","start":"452.13","dur":"1.83"},{"text":"It's also very capable of\nhistorical themed footage.","start":"453.96","dur":"2.94"},{"text":"So this is supposed to be\nCalifornia during the Gold Rush.","start":"456.9","dur":"4.05"},{"text":"It's AI generated but\nit could totally pass","start":"460.95","dur":"2.4"},{"text":"for the opening scene in an old Western","start":"463.35","dur":"1.83"},{"text":"with the right music over it.","start":"465.18","dur":"1.35"},{"text":"How long until an entire ad,","start":"466.53","dur":"1.35"},{"text":"every single shot is\ncompletely generated with AI?","start":"467.88","dur":"3.21"},{"text":"Or what about an entire YouTube\nvideo or an entire movie?","start":"471.09","dur":"3.42"},{"text":"I'm tempted to say like we're\na long way away from that","start":"474.51","dur":"1.896"},{"text":"because you know, this\nstill has flaws clearly","start":"476.406","dur":"2.994"},{"text":"and there's no sound,","start":"479.4","dur":"0.91"},{"text":"and there's a long way to go\nwith the prompt engineering","start":"480.31","dur":"2.51"},{"text":"to iron these things out.","start":"482.82","dur":"2.13"},{"text":"But then again, the spaghetti\nwas like a year ago.","start":"484.95","dur":"4.26"},{"text":"Now actually like that\nOpenAI, on their website,","start":"489.21","dur":"2.22"},{"text":"they show some of the downfalls too","start":"491.43","dur":"2.07"},{"text":"of this particular model.","start":"493.5","dur":"1.92"},{"text":"And because who would know better","start":"495.42","dur":"1.2"},{"text":"than the people who have been using it?","start":"496.62","dur":"1.44"},{"text":"This is a very private\ntool, by the way, right now.","start":"498.06","dur":"2.16"},{"text":"It's in super limited access,","start":"500.22","dur":"1.38"},{"text":"so it's in the hands of red teamers,","start":"501.6","dur":"1.907"},{"text":"which basically means people\ntesting it, pushing the limits,","start":"503.507","dur":"3.463"},{"text":"trying to break it, and\na few trusted creators.","start":"506.97","dur":"2.796"},{"text":"But they have found plenty\nof weird edge stuff.","start":"509.766","dur":"3.894"},{"text":"Like this clip here of a\nbunch of gray wolf pups","start":"513.66","dur":"3.27"},{"text":"looks normal at first","start":"516.93","dur":"0.93"},{"text":"but then it's pretty clear\nthat something's kinda off","start":"517.86","dur":"1.95"},{"text":"with the way they're just\nkinda appearing out of nowhere","start":"519.81","dur":"2.67"},{"text":"and walking through each other.","start":"522.48","dur":"1.86"},{"text":"That's kinda weird.","start":"524.34","dur":"1.14"},{"text":"Or this clip of a guy\nrunning on a treadmill,","start":"525.48","dur":"2.31"},{"text":"which I mean, I don't\nreally have to say much more","start":"527.79","dur":"1.92"},{"text":"about why this one is weird.","start":"529.71","dur":"1.2"},{"text":"But this is my favorite one, again,","start":"530.91","dur":"1.26"},{"text":"so again, just try to put\nyourself in the mind of someone","start":"532.17","dur":"2.73"},{"text":"who's not expecting AI.","start":"534.9","dur":"1.71"},{"text":"You're just scrolling through Facebook","start":"536.61","dur":"3"},{"text":"or Twitter or something, right?","start":"539.61","dur":"1.86"},{"text":"So you just see this video.","start":"541.47","dur":"0.9"},{"text":"So first I just want\nyou to watch this clip","start":"542.37","dur":"1.38"},{"text":"as if it's just a stock video you found","start":"543.75","dur":"1.92"},{"text":"of a grandma celebrating her birthday.","start":"545.67","dur":"2.01"},{"text":"And just try to think like,","start":"547.68","dur":"1.65"},{"text":"I wonder what birthday\nshe's celebrating, right?","start":"549.33","dur":"2.16"},{"text":"I don't know, how old do you think she is?","start":"551.49","dur":"1.14"},{"text":"60?","start":"552.63","dur":"1.02"},{"text":"65?","start":"553.65","dur":"0.833"},{"text":"Maybe it's the big 70.","start":"554.483","dur":"1.237"},{"text":"She seems to really like that cake.","start":"555.72","dur":"1.62"},{"text":"Now, did you see it?","start":"557.34","dur":"2.31"},{"text":"Did you catch that?","start":"559.65","dur":"1.241"},{"text":"I'm gonna play it again,","start":"560.891","dur":"1.249"},{"text":"but this time, watch the video","start":"562.14","dur":"2.13"},{"text":"knowing that AI generated\nphotos and videos","start":"564.27","dur":"3.42"},{"text":"have trouble accurately doing hands.","start":"567.69","dur":"4.86"},{"text":"I'll play it again.","start":"572.55","dur":"0.833"},{"text":"And now it feels super obvious\nlike every time you watch it,","start":"573.383","dur":"4.087"},{"text":"watch a different set of hands,\nit gets weirder and weirder.","start":"577.47","dur":"2.94"},{"text":"You can watch it like five\ntimes and there's dead giveaway","start":"580.41","dur":"2.37"},{"text":"after dead giveaway,","start":"582.78","dur":"1.17"},{"text":"not even mentioning the\nweird inconsistencies","start":"583.95","dur":"1.8"},{"text":"with the direction of\nthe wind on the candles.","start":"585.75","dur":"3.09"},{"text":"But even as I'm saying all that,","start":"588.84","dur":"1.53"},{"text":"even as it's coming outta my mouth,","start":"590.37","dur":"1.44"},{"text":"I can't help but remember\nthat 12 months ago","start":"591.81","dur":"2.85"},{"text":"we were critiquing this.","start":"594.66","dur":"1.992"},{"text":"(Will laughing)","start":"596.652","dur":"1.608"},{"text":"So what does this all mean?","start":"598.26","dur":"2.1"},{"text":"Well, I mean, there's what it means now","start":"600.36","dur":"2.34"},{"text":"and there's what it means for the future.","start":"602.7","dur":"2.31"},{"text":"Now, Sora, this thing that they've made","start":"605.01","dur":"3.18"},{"text":"is clearly a really impressive\nvideo generation AI tool","start":"608.19","dur":"4.41"},{"text":"that is both going to fool\npeople and also be very useful.","start":"612.6","dur":"5"},{"text":"There's also a watermark\nin the bottom corner","start":"618.082","dur":"3.068"},{"text":"of every video generated by it.","start":"621.15","dur":"1.41"},{"text":"So if you see one of those videos","start":"622.56","dur":"1.23"},{"text":"and ideally it hasn't been cropped out,","start":"623.79","dur":"2.28"},{"text":"then that's at least a\npretty clear indicator","start":"626.07","dur":"1.83"},{"text":"that it's AI generated.","start":"627.9","dur":"1.05"},{"text":"It's a Sora video.","start":"628.95","dur":"0.93"},{"text":"But also, I do think they're\ngonna have to be very careful","start":"629.88","dur":"3.54"},{"text":"with this, they're gonna have\na whole bunch of safety stuff","start":"633.42","dur":"2.19"},{"text":"to keep in mind.","start":"635.61","dur":"0.833"},{"text":"I think they'll probably\nhave to be even more safe","start":"636.443","dur":"1.477"},{"text":"than DALL.E.","start":"637.92","dur":"0.99"},{"text":"Like you shouldn't be able to\ngenerate people's likenesses.","start":"638.91","dur":"3.45"},{"text":"Like you shouldn't be\nable to make a politician","start":"642.36","dur":"1.62"},{"text":"look like they're doing\nsomething on video,","start":"643.98","dur":"1.65"},{"text":"especially this year.","start":"645.63","dur":"1.98"},{"text":"You probably won't be able to make","start":"647.61","dur":"1.35"},{"text":"Will Smith eating spaghetti,","start":"648.96","dur":"1.208"},{"text":"but it also definitely\nmeans stock video generation","start":"650.168","dur":"5"},{"text":"is absolutely going to take a\ndent out of video licensing.","start":"656.31","dur":"4.74"},{"text":"Like I can basically guarantee that.","start":"661.05","dur":"1.38"},{"text":"Like logistically, why would\nanyone making something","start":"662.43","dur":"2.82"},{"text":"pay for footage of a house in the cliffs","start":"665.25","dur":"2.43"},{"text":"when they can generate one for free","start":"667.68","dur":"2.55"},{"text":"or for a small subscription price?","start":"670.23","dur":"1.71"},{"text":"Like that is the real scary\npart of what this tool implies.","start":"671.94","dur":"3.09"},{"text":"But in the future, it gets\npretty existential, man.","start":"675.03","dur":"4.86"},{"text":"I mean, okay, if this\nis trained on all videos","start":"679.89","dur":"3.21"},{"text":"that have ever been made by humans,","start":"683.1","dur":"2.16"},{"text":"then surely it can't be\ninnovative or creative","start":"685.26","dur":"2.73"},{"text":"in ways that humans haven't\nalready been, right?","start":"687.99","dur":"4.923"},{"text":"I don't know.","start":"693.854","dur":"0.886"},{"text":"Either way, I'll have all the links below","start":"694.74","dur":"1.229"},{"text":"for all the Sora stuff, for OpenAI stuff,","start":"695.969","dur":"2.311"},{"text":"and I guess I'll talk to you next year","start":"698.28","dur":"1.74"},{"text":"when we look back and go,","start":"700.02","dur":"1.567"},{"text":""Remember that first version of Sora","start":"701.587","dur":"2.76"},{"text":""and how bad those wolf pups looked","start":"704.347","dur":"1.83"},{"text":""when they spawned out of nowhere?"","start":"706.177","dur":"1.75"},{"text":"Just remember, this is the\nworst that this technology","start":"708.81","dur":"1.491"},{"text":"is going to be from here on out.","start":"710.301","dur":"2.562"},{"text":"Thanks for watching.","start":"713.91","dur":"1.71"},{"text":"Catch you the next one, peace.","start":"715.62","dur":"2.116"},{"text":"(bright upbeat music)","start":"717.736","dur":"3.25"}]}}

Would you like to work on this issue?

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

github-actions[bot] commented 4 months ago

We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.

amitguptagwl commented 4 months ago

What version of the library do you use? Does it work when you don't set textNodeName: "text",?

amitguptagwl commented 4 months ago

parser supports only string.

ledlamp commented 4 months ago

it is string

ledlamp commented 4 months ago

since youtube url expire.. try this code on https://npm.runkit.com/fast-xml-parser

var {XMLParser} = require("fast-xml-parser")

var parser = new XMLParser({
    ignoreAttributes: false,
    textNodeName: "text",
    attributeNamePrefix: ""
});

var xml = `
<?xml version="1.0" encoding="utf-8" ?><transcript><text start="0.48" dur="4.04">hello everyone this is your daily dose</text><text start="2.36" dur="4.32">of Internet the police in Peru dressed</text><text start="4.52" dur="4.96">up on Valentine&amp;#39;s Day to get a suspect</text><text start="6.68" dur="2.8">to come out of their</text><text start="12.24" dur="5.879">house she thought she had a secret admir</text><text start="15.16" dur="2.959">but got arrested in</text><text start="23.96" dur="6.639">St I got it this</text><text start="28.279" dur="5.201">time I got it this</text><text start="30.599" dur="2.881">oh</text><text start="37.52" dur="5.48">my this guy put an electric muscle</text><text start="40" dur="3">stimulator on his</text><text start="58.92" dur="3.959">face</text><text start="60.76" dur="6.48">hold okay so listen up I&amp;#39;m not going to</text><text start="62.879" dur="6.801">say this again 6th fifth 4th 3D second 1</text><text start="67.24" dur="4.84">and then reverse all the way over and up</text><text start="69.68" dur="5.2">there&amp;#39;s your clutch break gas now you&amp;#39;re</text><text start="72.08" dur="5.2">ready you got</text><text start="74.88" dur="5.279">this this has to be the weirdest sound</text><text start="77.28" dur="2.879">I&amp;#39;ve ever heard from a</text><text start="88.84" dur="3">choir</text><text start="108.68" dur="3.68">how do you even end up in this type of</text><text start="118.28" dur="9.319">situation want to hug him I wish I could</text><text start="121.759" dur="9.881">yeah and kiss him yeah cuz you love him</text><text start="127.599" dur="4.041">yeah well was your dad&amp;#39;s</text><text start="131.84" dur="4.24">dead bro No One Believes me that my dog</text><text start="134.239" dur="3.801">is scared of Kim Jong-un he does not</text><text start="136.08" dur="4.239">like him who is this</text><text start="138.04" dur="5.839">Johnny who is</text><text start="140.319" dur="6.481">that yeah you tell</text><text start="143.879" dur="7.241">him yeah you tell this baby gorilla</text><text start="146.8" dur="7.4">really wants this toy eat it</text><text start="151.12" dur="5.64">yeah I want that I</text><text start="154.2" dur="4.92">know I found a company that makes really</text><text start="156.76" dur="2.36">trippy</text><text start="163.48" dur="3.679">vases this woman somehow gave birth to a</text><text start="166.2" dur="3.679">giant</text><text start="167.159" dur="6.841">baby here he</text><text start="169.879" dur="6.921">is and oh sorry baby I can barely hold</text><text start="174" dur="6.08">him but anyways he is the last time we</text><text start="176.8" dur="5.439">checked he was 24.4 lb this guy proposed</text><text start="180.08" dur="6.92">to his girlfriend at a waffle house I</text><text start="182.239" dur="4.761">just have one question will you marry</text><text start="190.08" dur="3.64">me I got</text><text start="195.08" dur="5.04">you what&amp;#39; you say I will</text><text start="205.08" dur="4.799">okay that is the end of this video we</text><text start="207.64" dur="6.599">hope you enjoyed and I&amp;#39;ll see you guys</text><text start="209.879" dur="4.36">again very very soon later</text></transcript>`;

console.log(JSON.stringify(parser.parse(xml)));

outputs:

{"?xml":{"version":"1.0","encoding":"utf-8"},"transcript":"[object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object]"}

also try this, same issue:

var {XMLParser} = require("fast-xml-parser")

var parser = new XMLParser({
    ignoreAttributes: false,
    textNodeName: "asdf",
    attributeNamePrefix: ""
});

var xml = `
<?xml version="1.0" encoding="utf-8" ?><transcript><asdf start="0.48" dur="4.04">hello everyone this is your daily dose</asdf><asdf start="2.36" dur="4.32">of Internet the police in Peru dressed</asdf><asdf start="4.52" dur="4.96">up on Valentine&amp;#39;s Day to get a suspect</asdf><asdf start="6.68" dur="2.8">to come out of their</asdf><asdf start="12.24" dur="5.879">house she thought she had a secret admir</asdf><asdf start="15.16" dur="2.959">but got arrested in</asdf><asdf start="23.96" dur="6.639">St I got it this</asdf><asdf start="28.279" dur="5.201">time I got it this</asdf><asdf start="30.599" dur="2.881">oh</asdf><asdf start="37.52" dur="5.48">my this guy put an electric muscle</asdf><asdf start="40" dur="3">stimulator on his</asdf><asdf start="58.92" dur="3.959">face</asdf><asdf start="60.76" dur="6.48">hold okay so listen up I&amp;#39;m not going to</asdf><asdf start="62.879" dur="6.801">say this again 6th fifth 4th 3D second 1</asdf><asdf start="67.24" dur="4.84">and then reverse all the way over and up</asdf><asdf start="69.68" dur="5.2">there&amp;#39;s your clutch break gas now you&amp;#39;re</asdf><asdf start="72.08" dur="5.2">ready you got</asdf><asdf start="74.88" dur="5.279">this this has to be the weirdest sound</asdf><asdf start="77.28" dur="2.879">I&amp;#39;ve ever heard from a</asdf><asdf start="88.84" dur="3">choir</asdf><asdf start="108.68" dur="3.68">how do you even end up in this type of</asdf><asdf start="118.28" dur="9.319">situation want to hug him I wish I could</asdf><asdf start="121.759" dur="9.881">yeah and kiss him yeah cuz you love him</asdf><asdf start="127.599" dur="4.041">yeah well was your dad&amp;#39;s</asdf><asdf start="131.84" dur="4.24">dead bro No One Believes me that my dog</asdf><asdf start="134.239" dur="3.801">is scared of Kim Jong-un he does not</asdf><asdf start="136.08" dur="4.239">like him who is this</asdf><asdf start="138.04" dur="5.839">Johnny who is</asdf><asdf start="140.319" dur="6.481">that yeah you tell</asdf><asdf start="143.879" dur="7.241">him yeah you tell this baby gorilla</asdf><asdf start="146.8" dur="7.4">really wants this toy eat it</asdf><asdf start="151.12" dur="5.64">yeah I want that I</asdf><asdf start="154.2" dur="4.92">know I found a company that makes really</asdf><asdf start="156.76" dur="2.36">trippy</asdf><asdf start="163.48" dur="3.679">vases this woman somehow gave birth to a</asdf><asdf start="166.2" dur="3.679">giant</asdf><asdf start="167.159" dur="6.841">baby here he</asdf><asdf start="169.879" dur="6.921">is and oh sorry baby I can barely hold</asdf><asdf start="174" dur="6.08">him but anyways he is the last time we</asdf><asdf start="176.8" dur="5.439">checked he was 24.4 lb this guy proposed</asdf><asdf start="180.08" dur="6.92">to his girlfriend at a waffle house I</asdf><asdf start="182.239" dur="4.761">just have one question will you marry</asdf><asdf start="190.08" dur="3.64">me I got</asdf><asdf start="195.08" dur="5.04">you what&amp;#39; you say I will</asdf><asdf start="205.08" dur="4.799">okay that is the end of this video we</asdf><asdf start="207.64" dur="6.599">hope you enjoyed and I&amp;#39;ll see you guys</asdf><asdf start="209.879" dur="4.36">again very very soon later</asdf></transcript>`;

console.log(JSON.stringify(parser.parse(xml)));

the problem is if textNodeName is set to the same as the node name, it breaks...

but I want output like this.

{"?xml":{"version":"1.0","encoding":"utf-8"},"transcript":{"text":[{"text":"hello everyone this is your daily dose","start":"0.48","dur":"4.04"},{"text":"of Internet the police in Peru dressed","start":"2.36","dur":"4.32"},{"text":"up on Valentine&#39;s Day to get a suspect","start":"4.52","dur":"4.96"},{"text":"to come out of their","start":"6.68","dur":"2.8"},{"text":"house she thought she had a secret admir","start":"12.24","dur":"5.879"},{"text":"but got arrested in","start":"15.16","dur":"2.959"},{"text":"St I got it this","start":"23.96","dur":"6.639"},{"text":"time I got it this","start":"28.279","dur":"5.201"},{"text":"oh","start":"30.599","dur":"2.881"},{"text":"my this guy put an electric muscle","start":"37.52","dur":"5.48"},{"text":"stimulator on his","start":"40","dur":"3"},{"text":"face","start":"58.92","dur":"3.959"},{"text":"hold okay so listen up I&#39;m not going to","start":"60.76","dur":"6.48"},{"text":"say this again 6th fifth 4th 3D second 1","start":"62.879","dur":"6.801"},{"text":"and then reverse all the way over and up","start":"67.24","dur":"4.84"},{"text":"there&#39;s your clutch break gas now you&#39;re","start":"69.68","dur":"5.2"},{"text":"ready you got","start":"72.08","dur":"5.2"},{"text":"this this has to be the weirdest sound","start":"74.88","dur":"5.279"},{"text":"I&#39;ve ever heard from a","start":"77.28","dur":"2.879"},{"text":"choir","start":"88.84","dur":"3"},{"text":"how do you even end up in this type of","start":"108.68","dur":"3.68"},{"text":"situation want to hug him I wish I could","start":"118.28","dur":"9.319"},{"text":"yeah and kiss him yeah cuz you love him","start":"121.759","dur":"9.881"},{"text":"yeah well was your dad&#39;s","start":"127.599","dur":"4.041"},{"text":"dead bro No One Believes me that my dog","start":"131.84","dur":"4.24"},{"text":"is scared of Kim Jong-un he does not","start":"134.239","dur":"3.801"},{"text":"like him who is this","start":"136.08","dur":"4.239"},{"text":"Johnny who is","start":"138.04","dur":"5.839"},{"text":"that yeah you tell","start":"140.319","dur":"6.481"},{"text":"him yeah you tell this baby gorilla","start":"143.879","dur":"7.241"},{"text":"really wants this toy eat it","start":"146.8","dur":"7.4"},{"text":"yeah I want that I","start":"151.12","dur":"5.64"},{"text":"know I found a company that makes really","start":"154.2","dur":"4.92"},{"text":"trippy","start":"156.76","dur":"2.36"},{"text":"vases this woman somehow gave birth to a","start":"163.48","dur":"3.679"},{"text":"giant","start":"166.2","dur":"3.679"},{"text":"baby here he","start":"167.159","dur":"6.841"},{"text":"is and oh sorry baby I can barely hold","start":"169.879","dur":"6.921"},{"text":"him but anyways he is the last time we","start":"174","dur":"6.08"},{"text":"checked he was 24.4 lb this guy proposed","start":"176.8","dur":"5.439"},{"text":"to his girlfriend at a waffle house I","start":"180.08","dur":"6.92"},{"text":"just have one question will you marry","start":"182.239","dur":"4.761"},{"text":"me I got","start":"190.08","dur":"3.64"},{"text":"you what&#39; you say I will","start":"195.08","dur":"5.04"},{"text":"okay that is the end of this video we","start":"205.08","dur":"4.799"},{"text":"hope you enjoyed and I&#39;ll see you guys","start":"207.64","dur":"6.599"},{"text":"again very very soon later","start":"209.879","dur":"4.36"}]}}

instead, i have to get output like this, with default textNodeName or anything else

{"?xml":{"version":"1.0","encoding":"utf-8"},"transcript":{"text":[{"#text":"hello everyone this is your daily dose","start":"0.48","dur":"4.04"},{"#text":"of Internet the police in Peru dressed","start":"2.36","dur":"4.32"},{"#text":"up on Valentine&#39;s Day to get a suspect","start":"4.52","dur":"4.96"},{"#text":"to come out of their","start":"6.68","dur":"2.8"},{"#text":"house she thought she had a secret admir","start":"12.24","dur":"5.879"},{"#text":"but got arrested in","start":"15.16","dur":"2.959"},{"#text":"St I got it this","start":"23.96","dur":"6.639"},{"#text":"time I got it this","start":"28.279","dur":"5.201"},{"#text":"oh","start":"30.599","dur":"2.881"},{"#text":"my this guy put an electric muscle","start":"37.52","dur":"5.48"},{"#text":"stimulator on his","start":"40","dur":"3"},{"#text":"face","start":"58.92","dur":"3.959"},{"#text":"hold okay so listen up I&#39;m not going to","start":"60.76","dur":"6.48"},{"#text":"say this again 6th fifth 4th 3D second 1","start":"62.879","dur":"6.801"},{"#text":"and then reverse all the way over and up","start":"67.24","dur":"4.84"},{"#text":"there&#39;s your clutch break gas now you&#39;re","start":"69.68","dur":"5.2"},{"#text":"ready you got","start":"72.08","dur":"5.2"},{"#text":"this this has to be the weirdest sound","start":"74.88","dur":"5.279"},{"#text":"I&#39;ve ever heard from a","start":"77.28","dur":"2.879"},{"#text":"choir","start":"88.84","dur":"3"},{"#text":"how do you even end up in this type of","start":"108.68","dur":"3.68"},{"#text":"situation want to hug him I wish I could","start":"118.28","dur":"9.319"},{"#text":"yeah and kiss him yeah cuz you love him","start":"121.759","dur":"9.881"},{"#text":"yeah well was your dad&#39;s","start":"127.599","dur":"4.041"},{"#text":"dead bro No One Believes me that my dog","start":"131.84","dur":"4.24"},{"#text":"is scared of Kim Jong-un he does not","start":"134.239","dur":"3.801"},{"#text":"like him who is this","start":"136.08","dur":"4.239"},{"#text":"Johnny who is","start":"138.04","dur":"5.839"},{"#text":"that yeah you tell","start":"140.319","dur":"6.481"},{"#text":"him yeah you tell this baby gorilla","start":"143.879","dur":"7.241"},{"#text":"really wants this toy eat it","start":"146.8","dur":"7.4"},{"#text":"yeah I want that I","start":"151.12","dur":"5.64"},{"#text":"know I found a company that makes really","start":"154.2","dur":"4.92"},{"#text":"trippy","start":"156.76","dur":"2.36"},{"#text":"vases this woman somehow gave birth to a","start":"163.48","dur":"3.679"},{"#text":"giant","start":"166.2","dur":"3.679"},{"#text":"baby here he","start":"167.159","dur":"6.841"},{"#text":"is and oh sorry baby I can barely hold","start":"169.879","dur":"6.921"},{"#text":"him but anyways he is the last time we","start":"174","dur":"6.08"},{"#text":"checked he was 24.4 lb this guy proposed","start":"176.8","dur":"5.439"},{"#text":"to his girlfriend at a waffle house I","start":"180.08","dur":"6.92"},{"#text":"just have one question will you marry","start":"182.239","dur":"4.761"},{"#text":"me I got","start":"190.08","dur":"3.64"},{"#text":"you what&#39; you say I will","start":"195.08","dur":"5.04"},{"#text":"okay that is the end of this video we","start":"205.08","dur":"4.799"},{"#text":"hope you enjoyed and I&#39;ll see you guys","start":"207.64","dur":"6.599"},{"#text":"again very very soon later","start":"209.879","dur":"4.36"}]}}

and then I have to convert this afterwards.

ledlamp commented 4 months ago

better examples

var {XMLParser} = require("fast-xml-parser")

var parser = new XMLParser({
    textNodeName: "text",
});

var xml = `<list><text>foo</text><text>bar</text></list>`;

console.log(parser.parse(xml));
// output: {list: "[object Object][object Object]"}

var parser = new XMLParser({
    textNodeName: "ttext",
});
console.log(parser.parse(xml));
// output: {list: {text: ["foo", "bar"]}}

var parser = new XMLParser({
    textNodeName: "ttext",
    ignoreAttributes: false
});
var xml = `<list><text x="1">foo</text><text x="2">bar</text></list>`;
console.log(parser.parse(xml));
// output: {list: {text: [{ttext: "foo", @_x: "1"}, {ttext: "bar", @_x: "2"}]}}

var parser = new XMLParser({
    textNodeName: "text",
    ignoreAttributes: false
});
console.log(parser.parse(xml));
// output: {list: "[object Object][object Object]"}

Although textNodeName is only useful with ignoreAttributes: false, the issue happens even with attributes ignored.

This happening with version 4.3.2.

ledlamp commented 4 months ago

Although it can be worked around if the parsed document is of a known structure, arbitrary xml could cause unexpected bug. For example, xml with <#text></#text> will break with default settings.

var {XMLParser} = require("fast-xml-parser")
var parser = new XMLParser();
var xml = `<list><#text>foo</#text><#text>bar</#text></list>`;
console.log(parser.parse(xml));

output:

{list: "[object Object][object Object]"}
amitguptagwl commented 4 months ago

Parser creates temporary nodes to separate text value of tag with with other nested tags. I tried one of your example which has the same name that is used in tag name as well. In such condition, you should choose different name to store tag value. Eg: @text

#text is not expected as a tag value, Hence, it is used as reserved name to store tag value. If you are expecting tags with this name, you should change the property value