所以我开始使用 xml 和 SAX 解析器,现在我试图弄清楚它是如何工作的,我熟悉 JSON,但这似乎不像 JSON 那样工作。所以这是我正在使用的代码
package com.myalbion.gamedataextractor.handlers;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.myalbion.gamedataextractor.Main;
import com.myalbion.gamedataextractor.datatables.Language;
import com.myalbion.gamedataextractor.datatables.Localized;
import com.myalbion.gamedataextractor.datatables.XMLFile;
public class LocalizationXMLFileHandler extends DefaultHandler {
private String temp;
Localized localized;
List<Localized> localizedList;
Map<Language, String> tempMap;
/*
* When the parser encounters plain text (not XML elements),
* it calls(this method, which accumulates them in a string buffer
*/
public void characters(char[] buffer, int start, int length) {
temp = new String(buffer, start, length);
}
/*
* Every time the parser encounters the beginning of a new element,
* it calls this method, which resets the string buffer
*/
public void startElement(String uri, String localName,
String qName, Attributes attributes) throws SAXException {
temp = "";
if (qName.equalsIgnoreCase("tu")) {
localized = new Localized();
localized.setUniqueName(attributes.getValue("tuid"));
} else if(qName.equalsIgnoreCase("tuv")) {
tempMap.put(Language.getLanguageFromCode(attributes.getValue("xml:lang")), )
}
}
}
}
我正在尝试将此 xml 文件中的数据提取到包含语言枚举和本地化名称的 tempMap 中。
精慕HU
相关分类