<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to fetch and parse XML data in the new UI's (e.g. Notebooks) code tile? in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218809#M421</link>
    <description>&lt;P&gt;You can also use this tiny xml parser library(&lt;A href="https://github.com/TobiasNickel/tXml" target="_blank" rel="noopener"&gt;https://github.com/TobiasNickel/tXml&lt;/A&gt;) in app functions/Notebook. Just copy the code from the github and add it inline in your app function as following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;// tXml code here

// your app function logic
export default async function (payload: unknown = undefined) {
  const apiUrl = 'https://mocktarget.apigee.net/xml';
  const response = await fetch(apiUrl);
  const result = await response.text()
  const parsedData = txml.simplify(txml.parse(result));
  return parsedData.city;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;This will work, however it isn't a good idea.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jul 2023 08:53:18 GMT</pubDate>
    <dc:creator>imsingh</dc:creator>
    <dc:date>2023-07-24T08:53:18Z</dc:date>
    <item>
      <title>How to fetch and parse XML data in the new UI's (e.g. Notebooks) code tile?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218718#M418</link>
      <description>&lt;P data-pm-slice="1 1 []"&gt;I found a public api with XML mock data: &lt;A href="https://mocktarget.apigee.net/xml" target="_blank"&gt;https://mocktarget.apigee.net/xml&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;root&amp;gt;
  &amp;lt;city&amp;gt;San Jose&amp;lt;/city&amp;gt;
  &amp;lt;firstName&amp;gt;John&amp;lt;/firstName&amp;gt;
  &amp;lt;lastName&amp;gt;Doe&amp;lt;/lastName&amp;gt;
  &amp;lt;state&amp;gt;CA&amp;lt;/state&amp;gt;
&amp;lt;/root&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;would like to fetch and access the data within &amp;lt;city&amp;gt;.&lt;/P&gt;
&lt;P&gt;I tried the following, but DOMParser is not defined.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;export default async function () {
  const apiUrl = 'https://mocktarget.apigee.net/xml';
  const response = await fetch(apiUrl);
  const result = await response.text()
  let parser = new DOMParser(),
			xmlDoc = parser.parseFromString (result, 'text/xml');
  return xmlDoc.getElementsByTagName ('city');
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;{
  "error": {
    "code": 540,
    "message": "Execution crashed.",
    "details": {
      "logs": "",
      "type": "UNCAUGHT_EXCEPTION",
      "message": "Uncaught (in promise) ReferenceError: DOMParser is not defined",
      "details": {
        "sourceLine": "  let parser = new DOMParser(),",
        "lineNumber": 7,
        "startColumn": 15,
        "stack": "Uncaught (in promise) ReferenceError: DOMParser is not defined\n    at default (script.ts:7:15)\n    at eventLoopTick (script.ts:11:1)"
      }
    }
  }
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Jul 2023 10:32:16 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218718#M418</guid>
      <dc:creator>kalelazic</dc:creator>
      <dc:date>2023-07-21T10:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to fetch and parse XML data in the new UI's (e.g. Notebooks) code tile?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218805#M419</link>
      <description>&lt;P&gt;Hi there&lt;/P&gt;
&lt;P&gt;At the moment, DOMParser API isn't supported in the app function. Take a look at the current supported APIs at&amp;nbsp;&lt;A href="https://developer.dynatrace.com/reference/javascript-runtime/" target="_blank" rel="noopener"&gt;https://developer.dynatrace.com/reference/javascript-runtime/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;However, you can send the full XML document as a text to the frontend and use DOM parser there. Take a look at the following example:&lt;/P&gt;
&lt;P&gt;1. App function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;export default async function (payload: unknown = undefined) {
  const apiUrl = 'https://mocktarget.apigee.net/xml';
  const response = await fetch(apiUrl);
  const result = await response.text()
  return result;
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Dynatrace App(frontend):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt; functions.call('xml-parser') //xml-parser is the name of the function
    .then((result) =&amp;gt; result.text())
    .then((result) =&amp;gt; {
      let parser = new DOMParser(),
        xmlDoc = parser.parseFromString(result, "text/xml");
      return xmlDoc.getElementsByTagName("city");
    }).then(result =&amp;gt; console.log(result[0].textContent)); // San Jose&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if it works!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 08:22:29 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218805#M419</guid>
      <dc:creator>imsingh</dc:creator>
      <dc:date>2023-07-24T08:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to fetch and parse XML data in the new UI's (e.g. Notebooks) code tile?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218807#M420</link>
      <description>&lt;P&gt;Hi Im! Thanks for the reply.&lt;BR /&gt;&lt;BR /&gt;I tried to apply this inside the existing app Notebooks - in the code tile.&amp;nbsp;&lt;BR /&gt;However, I guess you suggestion rather works for the custom app context. &lt;BR /&gt;I could not manage to embed this within the code tile alone.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 07:55:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218807#M420</guid>
      <dc:creator>kalelazic</dc:creator>
      <dc:date>2023-07-24T07:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to fetch and parse XML data in the new UI's (e.g. Notebooks) code tile?</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218809#M421</link>
      <description>&lt;P&gt;You can also use this tiny xml parser library(&lt;A href="https://github.com/TobiasNickel/tXml" target="_blank" rel="noopener"&gt;https://github.com/TobiasNickel/tXml&lt;/A&gt;) in app functions/Notebook. Just copy the code from the github and add it inline in your app function as following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;// tXml code here

// your app function logic
export default async function (payload: unknown = undefined) {
  const apiUrl = 'https://mocktarget.apigee.net/xml';
  const response = await fetch(apiUrl);
  const result = await response.text()
  const parsedData = txml.simplify(txml.parse(result));
  return parsedData.city;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;This will work, however it isn't a good idea.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 08:53:18 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/How-to-fetch-and-parse-XML-data-in-the-new-UI-s-e-g-Notebooks/m-p/218809#M421</guid>
      <dc:creator>imsingh</dc:creator>
      <dc:date>2023-07-24T08:53:18Z</dc:date>
    </item>
  </channel>
</rss>

