Angular 6 extract value from decoded string base 64










1















I've decoded a string in Base64 with xml2js library and i got this value :



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>


i cut the encode value because it's to long



I'm blocked for getting the value of xlink:href, is there any technics or library for getting the attribute ?



I mean i want to get this value only : data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=



Thank's










share|improve this question






















  • You could try using a regex to match only that part of the string. Something like /xlink:href="([^"]*)"/

    – Alex K
    Nov 15 '18 at 15:46






  • 1





    It's a svg you can parse it using DOMParser

    – JEY
    Nov 15 '18 at 15:59











  • @JEY that's probably the most robust solution :)

    – Alex K
    Nov 15 '18 at 16:03















1















I've decoded a string in Base64 with xml2js library and i got this value :



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>


i cut the encode value because it's to long



I'm blocked for getting the value of xlink:href, is there any technics or library for getting the attribute ?



I mean i want to get this value only : data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=



Thank's










share|improve this question






















  • You could try using a regex to match only that part of the string. Something like /xlink:href="([^"]*)"/

    – Alex K
    Nov 15 '18 at 15:46






  • 1





    It's a svg you can parse it using DOMParser

    – JEY
    Nov 15 '18 at 15:59











  • @JEY that's probably the most robust solution :)

    – Alex K
    Nov 15 '18 at 16:03













1












1








1








I've decoded a string in Base64 with xml2js library and i got this value :



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>


i cut the encode value because it's to long



I'm blocked for getting the value of xlink:href, is there any technics or library for getting the attribute ?



I mean i want to get this value only : data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=



Thank's










share|improve this question














I've decoded a string in Base64 with xml2js library and i got this value :



<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>


i cut the encode value because it's to long



I'm blocked for getting the value of xlink:href, is there any technics or library for getting the attribute ?



I mean i want to get this value only : data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=



Thank's







angular typescript base64






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 15:23









Stephanie JoyceStephanie Joyce

315




315












  • You could try using a regex to match only that part of the string. Something like /xlink:href="([^"]*)"/

    – Alex K
    Nov 15 '18 at 15:46






  • 1





    It's a svg you can parse it using DOMParser

    – JEY
    Nov 15 '18 at 15:59











  • @JEY that's probably the most robust solution :)

    – Alex K
    Nov 15 '18 at 16:03

















  • You could try using a regex to match only that part of the string. Something like /xlink:href="([^"]*)"/

    – Alex K
    Nov 15 '18 at 15:46






  • 1





    It's a svg you can parse it using DOMParser

    – JEY
    Nov 15 '18 at 15:59











  • @JEY that's probably the most robust solution :)

    – Alex K
    Nov 15 '18 at 16:03
















You could try using a regex to match only that part of the string. Something like /xlink:href="([^"]*)"/

– Alex K
Nov 15 '18 at 15:46





You could try using a regex to match only that part of the string. Something like /xlink:href="([^"]*)"/

– Alex K
Nov 15 '18 at 15:46




1




1





It's a svg you can parse it using DOMParser

– JEY
Nov 15 '18 at 15:59





It's a svg you can parse it using DOMParser

– JEY
Nov 15 '18 at 15:59













@JEY that's probably the most robust solution :)

– Alex K
Nov 15 '18 at 16:03





@JEY that's probably the most robust solution :)

– Alex K
Nov 15 '18 at 16:03












1 Answer
1






active

oldest

votes


















2














You can use DOMParser to parse the xml string. Then you can operate on the resulting Document as usual:






const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);








share|improve this answer























  • just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

    – JEY
    Nov 15 '18 at 16:04











  • @JEY looks like that works well too!

    – Alex K
    Nov 15 '18 at 16:10











  • I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

    – Stephanie Joyce
    Nov 15 '18 at 16:11










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322630%2fangular-6-extract-value-from-decoded-string-base-64%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can use DOMParser to parse the xml string. Then you can operate on the resulting Document as usual:






const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);








share|improve this answer























  • just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

    – JEY
    Nov 15 '18 at 16:04











  • @JEY looks like that works well too!

    – Alex K
    Nov 15 '18 at 16:10











  • I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

    – Stephanie Joyce
    Nov 15 '18 at 16:11















2














You can use DOMParser to parse the xml string. Then you can operate on the resulting Document as usual:






const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);








share|improve this answer























  • just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

    – JEY
    Nov 15 '18 at 16:04











  • @JEY looks like that works well too!

    – Alex K
    Nov 15 '18 at 16:10











  • I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

    – Stephanie Joyce
    Nov 15 '18 at 16:11













2












2








2







You can use DOMParser to parse the xml string. Then you can operate on the resulting Document as usual:






const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);








share|improve this answer













You can use DOMParser to parse the xml string. Then you can operate on the resulting Document as usual:






const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);








const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);





const xmlString = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="293" height="102"
viewBox="0 0 293 102"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" baseProfile="tiny">
<image
width="293"
height="102"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANS......pASYAAAAASUVORK5CYII=" />
</svg>`;

const domParser = new DOMParser();
const xmlDoc = domParser.parseFromString(xmlString, 'application/xml');
const imageElement = xmlDoc.getElementsByTagName('image')[0];
const hrefAttr = imageElement.getAttribute('xlink:href');
console.log(hrefAttr);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 16:01









Alex KAlex K

1,195610




1,195610












  • just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

    – JEY
    Nov 15 '18 at 16:04











  • @JEY looks like that works well too!

    – Alex K
    Nov 15 '18 at 16:10











  • I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

    – Stephanie Joyce
    Nov 15 '18 at 16:11

















  • just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

    – JEY
    Nov 15 '18 at 16:04











  • @JEY looks like that works well too!

    – Alex K
    Nov 15 '18 at 16:10











  • I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

    – Stephanie Joyce
    Nov 15 '18 at 16:11
















just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

– JEY
Nov 15 '18 at 16:04





just use querySelector and getAttributeNS like i did stackblitz.com/edit/typescript-yx3fyn

– JEY
Nov 15 '18 at 16:04













@JEY looks like that works well too!

– Alex K
Nov 15 '18 at 16:10





@JEY looks like that works well too!

– Alex K
Nov 15 '18 at 16:10













I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

– Stephanie Joyce
Nov 15 '18 at 16:11





I've use this : var urlImage = xml.match(/xlink:href="([^"]*)"/); var finalUrl = urlImage[1] and it works Thank's @Alex K and Jey for your solutions

– Stephanie Joyce
Nov 15 '18 at 16:11



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322630%2fangular-6-extract-value-from-decoded-string-base-64%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3