Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need the name of each layer in an .msd, but I could not find support using arcpy (ArcGIS 10.0). Is there a method I missed?

In the current workflow, since I am publishing the document, I use the REST service:

descriptionUrl = url + "/ArcGIS/rest/services/" + mapServer + "/MapServer?f=json"  
restResponseFp = urllib.urlopen(descriptionUrl)
mapDescription =json.load(restResponseFp)
layerNames = [str(layer["name"]) for layer in mapDescription["layers"]]
share|improve this question
up vote 4 down vote accepted
import zipfile
from xml.etree.cElementTree import iterparse

zz = zipfile.ZipFile('C:\\Temp\\')

serviceNames = []
for name in zz.namelist():
    if name == "DocumentInfo.xml" or name == "layers/layers.xml":
        for _event, elem in iterparse(
            if elem.tag == "Name":

Files associated with layers are named like this: layers/featureclassname.xml

Long service names are truncated to make the file name, so we must parse the file contents to handle all cases.

share|improve this answer
Thanks! Actually, I notice that since my service names are very long, the xml file name is truncated. Each file associated with a layer must be parsed for the "Name" element to reliably handle long service names. – Michael A. Jackson Nov 1 '11 at 5:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.