Few XML Helpers to deal in Typescript

Hi everyone here I am introducing some code to deal with xml data in javascript.

  // XML Helpers..
  getXmlTagValue(xmlString: string, TagName: string): any {
    const xmlDocument = (new DOMParser()).parseFromString(xmlString, 'application/xml');
    const tagValue = xmlDocument.getElementsByTagName(TagName)[0].childNodes[0].nodeValue;
    return tagValue;
  }

  getXmlTagList(xmlString: string, TagName: string): any {
    const xmlDocument = (new DOMParser()).parseFromString(xmlString, 'application/xml');
    const tagList = xmlDocument.getElementsByTagName(TagName);
    return tagList;
  }

  getElementsValueByTagName(Element: any, TagName: string): any {
    try {
      const ElementValue = Element.getElementsByTagName(TagName)[0];
      return ElementValue;

    } catch (error) {
    }
  }

Author Profile

PREM KUMAR
PREM KUMAR
Tech Lover , Open Src Dev , Dotnet Core, Ionic, Xamarin, Node, Angular2, Python, Opencv, AI, ML, Robotics, SignalR, Iot, Love Music, Cooking, Girls, Innovation.
Like
Like Love Haha Wow Sad Angry

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enable Notifications    Ok No thanks