-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategoryMembers.java
More file actions
27 lines (23 loc) · 896 Bytes
/
Copy pathCategoryMembers.java
File metadata and controls
27 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
public class CategoryMembers extends Api {
public int categoryMembers(String category) throws IOException{
String results = query("categorymembers", "&cmtitle=Category:" + category + "&cmlimit=max");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();
Document document = builder.parse( new InputSource( new StringReader( results ) ) );
Element root = document.getDocumentElement();
NodeList nList = root.getElementsByTagName("cm");
return nList.getLength();
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
}