<?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 Splitting dynamic text strings with XML tags in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448089#M35146</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a way to extract parts of text from a dynamic text using xml tags? What I would like to do is to extract the number from an mxd file name and write it to a text box inside arcmap which is the caption. Example:&lt;/P&gt;&lt;P&gt;filename: Fig_3_Test.mxd&lt;/P&gt;&lt;P&gt;caption:&amp;nbsp;&amp;lt;dyn type="document" property="name" split text start =3 end = 5/&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Nahide&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Jul 2017 17:00:44 GMT</pubDate>
    <dc:creator>Z__NahideAydin1</dc:creator>
    <dc:date>2017-07-28T17:00:44Z</dc:date>
    <item>
      <title>Splitting dynamic text strings with XML tags</title>
      <link>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448089#M35146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a way to extract parts of text from a dynamic text using xml tags? What I would like to do is to extract the number from an mxd file name and write it to a text box inside arcmap which is the caption. Example:&lt;/P&gt;&lt;P&gt;filename: Fig_3_Test.mxd&lt;/P&gt;&lt;P&gt;caption:&amp;nbsp;&amp;lt;dyn type="document" property="name" split text start =3 end = 5/&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Nahide&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Jul 2017 17:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448089#M35146</guid>
      <dc:creator>Z__NahideAydin1</dc:creator>
      <dc:date>2017-07-28T17:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dynamic text strings with XML tags</title>
      <link>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448090#M35147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nahide,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is an interesting question. It might be best asked in a different space since the GeoNet Help is for help with the geonet. Maybe move it to &lt;A href="https://community.esri.com/groups/cartography-and-maps?sr=search&amp;amp;searchId=13fd9f1d-f437-462f-9374-b1148b5ac150&amp;amp;searchIndex=1"&gt;https://community.esri.com/groups/cartography-and-maps?sr=search&amp;amp;searchId=13fd9f1d-f437-462f-9374-b1148b5ac150&amp;amp;searchIndex=1&lt;/A&gt;‌ or &lt;A href="https://community.esri.com/community/gis/managing-data?sr=search&amp;amp;searchId=28fe3f9f-473b-490a-963c-1126f912c492&amp;amp;searchIndex=0"&gt;https://community.esri.com/community/gis/managing-data?sr=search&amp;amp;searchId=28fe3f9f-473b-490a-963c-1126f912c492&amp;amp;searchIndex=0&lt;/A&gt;‌ ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2017 20:21:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448090#M35147</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2017-08-01T20:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dynamic text strings with XML tags</title>
      <link>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448091#M35148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nahide,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from a quick scan that sounds like Python &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;If I got it right you know the NAME of the element you want to fill, or can create one - then you should be able to use the &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/textelement-class.htm"&gt;TextElement Class&lt;/A&gt;. Dont think you can just use dynamic text.&lt;/P&gt;&lt;P&gt;Sure - you have to get the string part. If the document name has a structure as you say, something like this should do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;import arcpy,os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#do this in two lines - safe bet if Path can contain additional underscores&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;theName= str(mxd.filePath.split(os.sep)[-1:])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;# now extract the number from the mxd-name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;theTitle = str(theName.split("_")[-2]) #I assume a logic of _Number_ here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;# and given you have an element called map title ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;elm = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitle")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;# set the text&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;elm.text = TheTitle&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:46:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448091#M35148</guid>
      <dc:creator>GünterDörffel</dc:creator>
      <dc:date>2017-08-02T18:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dynamic text strings with XML tags</title>
      <link>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448092#M35149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Günter:&lt;/P&gt;&lt;P&gt;I thought so too. But I wanted try my luck to see if anybody was able to do something like that through XML tags. I did something different in the end. I used the dynamic txt tag field for the figure numbers and when they change the figure numbers, which they will, I will do something like this:&lt;/P&gt;&lt;P&gt;for mxd in MXDList:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;fileName = os.path.splitext(os.path.basename(mxd))[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;figNum = str(fileName.split("_") [-2]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;InMxd = arcpy.mapping.MapDocument(mxd)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;InMxd.tags = figNum&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;InMXD. save&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:26:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448092#M35149</guid>
      <dc:creator>Z__NahideAydin1</dc:creator>
      <dc:date>2017-08-02T19:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dynamic text strings with XML tags</title>
      <link>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448093#M35150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There you go! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Thanks for commenting again. Have fun!&amp;nbsp; Guenter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Aug 2017 07:37:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/splitting-dynamic-text-strings-with-xml-tags/m-p/448093#M35150</guid>
      <dc:creator>GünterDörffel</dc:creator>
      <dc:date>2017-08-03T07:37:44Z</dc:date>
    </item>
  </channel>
</rss>

