<?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>question Re: How I can print element in a xml String in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712514#M1048192</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to print xxx in the line&amp;nbsp;&lt;SPAN&gt;" &amp;lt;two att=\"xxx\"&amp;gt;abcd1234&amp;lt;/two&amp;gt;"+&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;and&amp;nbsp; yah or yyy in the given string&amp;nbsp;&lt;SPAN&gt;" &amp;lt;three boo=\"yah\" att=\"yyy\"&amp;gt;1234abcd&amp;lt;/three&amp;gt;" +&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;like some element in the xml string.&lt;/P&gt;&lt;P&gt;How can I get the desired output?&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2023 07:16:18 GMT</pubDate>
    <dc:creator>Suyash Joshi</dc:creator>
    <dc:date>2023-10-25T07:16:18Z</dc:date>
    <item>
      <title>How I can print element in a xml String</title>
      <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712502#M1048184</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I am stuck in a problem in which I want to print only a single element in code.&lt;/P&gt;&lt;P&gt;The code as follow:-&lt;/P&gt;&lt;P&gt;var xmlString = "&amp;lt;test&amp;gt;" +&lt;BR /&gt;" &amp;lt;one&amp;gt;" +&lt;BR /&gt;" &amp;lt;two att=\"xxx\"&amp;gt;abcd1234&amp;lt;/two&amp;gt;" +&lt;BR /&gt;" &amp;lt;three boo=\"yah\" att=\"yyy\"&amp;gt;1234abcd&amp;lt;/three&amp;gt;" +&lt;BR /&gt;" &amp;lt;two&amp;gt;another&amp;lt;/two&amp;gt;" +&lt;BR /&gt;" &amp;lt;/one&amp;gt;" +&lt;BR /&gt;" &amp;lt;number&amp;gt;1234&amp;lt;/number&amp;gt;" +&lt;BR /&gt;"&amp;lt;/test&amp;gt;";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be greatful&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suyash&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 07:23:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712502#M1048184</guid>
      <dc:creator>Suyash Joshi</dc:creator>
      <dc:date>2023-10-25T07:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: How I can print element in a xml String</title>
      <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712508#M1048189</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570576"&gt;@Suyash Joshi&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please explain what exactly you're trying to accomplish?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 07:12:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712508#M1048189</guid>
      <dc:creator>Peter Bodelier</dc:creator>
      <dc:date>2023-10-25T07:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How I can print element in a xml String</title>
      <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712514#M1048192</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to print xxx in the line&amp;nbsp;&lt;SPAN&gt;" &amp;lt;two att=\"xxx\"&amp;gt;abcd1234&amp;lt;/two&amp;gt;"+&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;and&amp;nbsp; yah or yyy in the given string&amp;nbsp;&lt;SPAN&gt;" &amp;lt;three boo=\"yah\" att=\"yyy\"&amp;gt;1234abcd&amp;lt;/three&amp;gt;" +&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;like some element in the xml string.&lt;/P&gt;&lt;P&gt;How can I get the desired output?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 07:16:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712514#M1048192</guid>
      <dc:creator>Suyash Joshi</dc:creator>
      <dc:date>2023-10-25T07:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: How I can print element in a xml String</title>
      <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712521#M1048195</link>
      <description>&lt;P&gt;You're going to need to use&amp;nbsp;&lt;A href="https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/no-namespace/c_XMLDocument2ScopedAPI#r_ScopedXMLDocument2GetDocumentElement?navFilter=XMLDocument2" target="_blank" rel="noopener"&gt;XMLDocument2 | ServiceNow Developers&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*
 * Retrieves the attribute value from the given XML.
 * Params:
 *  xmlDoc - XMLDocument2, XML document to parse
 * Returns:
 *  String, attribute value or null if not found
 */
function getAttributeKey (xmlDoc) {
  var node = xmlDoc.getNode("/test/one/two");
  if (node != null) {
    return node.getAttribute("att");
  } else {
    return null;
  }
}

// Example usage:

var xmlString = "&amp;lt;test&amp;gt;" +
                "  &amp;lt;one&amp;gt;" +
                "    &amp;lt;two att=\"xxx\"&amp;gt;abcd1234&amp;lt;/two&amp;gt;" +
                "    &amp;lt;three boo=\"yah\" att=\"yyy\"&amp;gt;1234abcd&amp;lt;/three&amp;gt;" +
                "    &amp;lt;two&amp;gt;another&amp;lt;/two&amp;gt;" +
                "  &amp;lt;/one&amp;gt;" +
                "  &amp;lt;number&amp;gt;1234&amp;lt;/number&amp;gt;" +
                "&amp;lt;/test&amp;gt;";

var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(xmlString);

var attribute = getAttributeKey(xmlDoc);
if (attribute != null) {
  gs.info("The attribute value is: " + attribute);
} else {
  gs.info("The attribute value is not found.");
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 07:32:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712521#M1048195</guid>
      <dc:creator>Peter Bodelier</dc:creator>
      <dc:date>2023-10-25T07:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: How I can print element in a xml String</title>
      <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712530#M1048201</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570576"&gt;@Suyash Joshi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the business requirement here?&lt;/P&gt;
&lt;P&gt;You can use XML parsing or convert that XML to JSON and then parse the JSON&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 07:37:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712530#M1048201</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2023-10-25T07:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: How I can print element in a xml String</title>
      <link>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712613#M1048232</link>
      <description>&lt;P&gt;I want to print only element now (&lt;SPAN&gt;abcd1234,&amp;nbsp;1234abcd,&amp;nbsp;another,&amp;nbsp;1234&amp;nbsp;&lt;/SPAN&gt;), My first requirement has fulfilled.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 08:35:15 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-i-can-print-element-in-a-xml-string/m-p/2712613#M1048232</guid>
      <dc:creator>Suyash Joshi</dc:creator>
      <dc:date>2023-10-25T08:35:15Z</dc:date>
    </item>
  </channel>
</rss>

