[mapserver-users] Re: Extract Layer Names from MapFile
Dash
jimlug at co.clackamas.or.us
Wed Feb 15 10:13:12 PST 2012
Well, I believe I figured it out using Java. I am able to use the URL Class
to get the xml from my GetCapabilites request. Then, I created an
InputStream from the URL Class and pass the InputStream object into my Java
XML parser. It's actually pretty slick. Next, I'll try and plug it in to a
JSP page. Thanks for all the advice and here is the codes for anyone else
who is interested.
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLReader {
public static void main (String[] args) {
try {
URL getCapabilities = new URL(<your getcapabilities wms request with
quotes>);
InputStream is = getCapabilities.openStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(is);
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("Layer");
for (int s = 0; s < nodeList.getLength(); s++) {
Node fstNode = nodeList.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element)fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("Name");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("MapFile Layer Name : " + ((Node)
fstNm.item(0)).getNodeValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Extract-Layer-Names-from-MapFile-tp4472664p4473199.html
Sent from the Mapserver - User mailing list archive at Nabble.com.
More information about the MapServer-users
mailing list