Advertisement
BullyATWiiplaza

Wii U Game Id Parser

Jan 7th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import org.w3c.dom.Document;
  2. import org.xml.sax.SAXException;
  3.  
  4. import javax.xml.parsers.DocumentBuilder;
  5. import javax.xml.parsers.DocumentBuilderFactory;
  6. import javax.xml.parsers.ParserConfigurationException;
  7. import java.io.File;
  8. import java.io.IOException;
  9.  
  10. public class GameDataParser
  11. {
  12.     private Document document;
  13.  
  14.     public GameDataParser(String metaXMLFilePath) throws ParserConfigurationException, IOException, SAXException
  15.     {
  16.         File metaXMLFile = new File(metaXMLFilePath);
  17.         DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
  18.         DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
  19.         document = documentBuilder.parse(metaXMLFile);
  20.     }
  21.  
  22.     public String getGameId() throws IOException, SAXException, ParserConfigurationException
  23.     {
  24.         String productCode = getProductCode();
  25.         String companyCode = getCompanyCode();
  26.  
  27.         return productCode + companyCode;
  28.     }
  29.  
  30.     private String getProductCode()
  31.     {
  32.         return getText("product_code", 6);
  33.     }
  34.  
  35.     private String getCompanyCode()
  36.     {
  37.         return getText("company_code", 2);
  38.     }
  39.  
  40.     private String getText(String tagName, int beginIndex)
  41.     {
  42.         return document.getElementsByTagName(tagName).item(0).getTextContent().substring(beginIndex);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement