//从XML文件中读取信息,并写入fw.
private void processFile(File file, FileWriter fw) throws Exception {
String sObject = "";
String dObject = "";
String sCondition = "";
String dCondition = "";
String sCardinality = "";
String dCardinality = "";
boolean isSourceFound = false;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element " +
doc.getDocumentElement().getNodeName());
String aoName = doc.getDocumentElement().getAttribute("Name");
System.out.println(aoName);
NodeList nodeLst = doc.getElementsByTagName("AssociationEnd");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element)fstNode;
String eo = fstElmnt.getAttribute("Name");
if (isSourceFound) {
dObject = eo;
} else {
sObject = eo;
}
String cardinality = fstElmnt.getAttribute("Cardinality");
if (cardinality.equals("-1")) {
cardinality = "*";
}
if (isSourceFound) {
dCardinality = cardinality;
} else {
sCardinality = cardinality;
}
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("AttrArray");
Element attElmnt = (Element)fstNmElmntLst.item(0);
NodeList itemNodes = attElmnt.getElementsByTagName("Item");
Element itemElmnt = (Element)itemNodes.item(0);
String condition = itemElmnt.getAttribute("Value");
if (isSourceFound) {
dCondition = condition;
} else {
sCondition = condition;
}
isSourceFound = !isSourceFound;
}
}
String Cardinality = sCardinality + "..." + dCardinality;
String joinCondion = sCondition + "=" + dCondition;
String outString =
aoName + "\t" + sObject + "\t" + dObject + "\t" + Cardinality + "\t" +
joinCondion + "\t" + "Y" + "\n";
System.out.println(outString);
fw.write(outString);
}
分享到:
- 2009-08-25 16:21
- 浏览 847
- 评论(0)
- 论坛回复 / 浏览 (0 / 1164)
- 查看更多
相关推荐
描述中的"xml file parser sample"提示我们这个压缩包可能包含了一个用于解析XML文件的示例程序。XML解析器是读取和解释XML文档的软件,它能将XML文件的内容转换为程序可以理解和处理的数据结构。 标签"zip"进一步...
parser.parse(new File("path_to_your_xml_file.xml"), handler); ``` 5. **XML Java API** `javax.xml.transform`包提供了用于转换XML的API,如将DOM转换为字符串,或者使用XSLT转换XML。`javax.xml.validation...
- "sample.cfg" 是一个示例配置文件,可能用于测试Parser的功能,开发者可以通过查看其内容了解Parser应如何正确解析不同类型的配置文件。 - "class_diagramm.dia" 可能是一个类图文件,通常用于描绘类库中的类及其...
XML的parser发展为两类:一种是"非确认类paeser",只检测文档是否遵守XML语法规则,是否用元素标识建立了文档树。另一种是"确认类paeser",它不但检测文档语法,结构树,而且比较解析你使用的元素标识是否遵守了相应...
Document doc = reader.read(new File("sample.xml")); Element root = doc.getRootElement(); List<Element> elements = root.elements(); for (Element e : elements) { System.out.println(e.getName() + ":...
jQGrid 3.5 jQuery UI 1.7.2 Lightness theme (get ...Sample static XML file (do not put this one into the 'url', it won't work) Complete JSON.php and XML.php parser mySQL script for rapid demo integration
parser.add_argument('--xml_path', default='Annotations', type=str, help='input xml label path') parser.add_argument('--txt_path', default='ImageSets', type=str, help='output txt label path') opt = ...
./data/2011/training/tac_kbp_2011_chinese_entity_linking_sample_and_training_queries.xml This file is a concatenation of the queries files originally released in LDC2011E46 (sample) and LDC2011E55...
The corpus is marked up for text categories, sample file numbers, paragraphs, sentences and tokens. Linguistic annotations undertaken on the corpus include tokenization and part-of-speech tagging. The...
javax.xml.stream javax.xml.stream.events javax.xml.stream.util javax.xml.transform 此包定义了用于处理转换指令,以及执行从源到结果的转换的一般 API。 javax.xml.transform.dom 此包实现特定于 DOM 的转换 ...
Sample.xml 12.XML操作类 XmlHelper XMLProcess 13.弹出消息类 MessageBox ShowMessageBox 14.导出Excel 操作类 DataToExcel ExcelHelper ExportExcel GridViewExport 15.分词辅助类 SegList 16.汉字转拼音 ...
Indicates to the parser which events your handler should be notified of. - **答案**:"C. Aids in interpreting the event parameter in an event handling procedure." - **解析**:这些保留字主要用于帮助...
* fixed: v2.84 sometimes chose incorrect XML file * fixed: v2.84 sometimes chose wrong m2ts playlist file * fixed: some actions were eventually applied twice when "-2pass" was used * fixed: AAC ...
Sample.xml 11.XML操作类 XmlHelper XMLProcess 12.弹出消息类 MessageBox ShowMessageBox 13.导出Excel 操作类 DataToExcel ExcelHelper ExportExcel GridViewExport 14.分词辅助类 SegList 15.汉字转拼音 ...
Axis2LogFile /usr/tmp/AxisLog Axis2MaxLogFileSize 200 Axis2LogLevel LOG_LEVEL SetHandler axis2_module ``` - 验证配置正确性,使用`apachectl configtest`命令,如果没有错误信息,则表示配置成功...
4)....Added "--el_injectjcl", "--el_createjcl", and "--el_createdbg" command-line options for ecc32/emake to inject JEDI/JCL debug info, create .jdbg file, and create .dbg file (Microsoft debug format...
Javascript小技巧一箩筐 事件源对象 event.srcElement.tagName event.srcElement.type ... 捕获释放 event.srcElement.setCapture();...event.srcElement.releaseCapture();... 根据鼠标获得元素: document....
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. # ###################### ### Query Language ### ###################### ## define query language ...