xml文件内容举例如下:
<cim:Pole rdf:ID="POLE_510030101802704">
<cim:IdentifiedObject.name>8</cim:IdentifiedObject.name>
<cim:IdentifiedObject.mRID>510030101802704</cim:IdentifiedObject.mRID>
<cim:PowerSystemResource.status>1</cim:PowerSystemResource.status>
<cim:PowerSystemResource.maintainDepart>17734F60505B35AAE055000000000001</cim:PowerSystemResource.maintainDepart>
<cim:PowerSystemResource.subType>10</cim:PowerSystemResource.subType>
<cim:Pole.material>水泥杆</cim:Pole.material>
<cim:PowerSystemResource.location>POINT(102.7367735 25.0628367)</cim:PowerSystemResource.location>
<cim:PowerSystemResource.PSRType rdf:resource="#PSRTYPE_338"/>
<cim:PowerSystemResource.BaseVoltage rdf:resource="#BASEVOL_10000"/>
</cim:Pole>
<cim:ACLineSegment rdf:ID="SEG_510100078565402">
<cim:IdentifiedObject.name>10kV新迎北线</cim:IdentifiedObject.name>
<cim:IdentifiedObject.mRID>510100078565402</cim:IdentifiedObject.mRID>
<cim:PowerSystemResource.status>1</cim:PowerSystemResource.status>
<cim:PowerSystemResource.maintainDepart>17734F60505B35AAE055000000000001</cim:PowerSystemResource.maintainDepart>
<cim:Equipment.model>YJLV22-3*300/3300</cim:Equipment.model>
<cim:ConductingEquipment.phases>ABC</cim:ConductingEquipment.phases>
<cim:Conductor.length>3.3</cim:Conductor.length>
<cim:ACLineSegment.prevPSRID>509030009340402</cim:ACLineSegment.prevPSRID>
<cim:ACLineSegment.nextPSRID>510030009385702</cim:ACLineSegment.nextPSRID>
<cim:PowerSystemResource.location>LINESTRING(102.7486359 25.072169,102.748384 25.0717219,102.7510958 25.0697485,102.7499847 25.0678077,102.7485527 25.0661262,102.7470821 25.0645664,102.7466453 25.0641534,102.7464284 25.0638831,102.7461224 25.0634344,102.7457629 25.0628997,102.7453173 25.0622134,102.7448895 25.0615598,102.744019 25.0602258,102.7430445 25.0585828,102.7422483 25.0577599,102.7414818 25.0569131,102.7396398 25.0565477,102.738852 25.0571201,102.7384201 25.0575919,102.7375095 25.0585887,102.737049 25.0590432,102.7360062 25.0600578,102.7348759 25.0610112)</cim:PowerSystemResource.location>
<cim:PowerSystemResource.PSRType rdf:resource="#PSRTYPE_311"/>
<cim:PowerSystemResource.BaseVoltage rdf:resource="#BASEVOL_10000"/>
<cim:Equipment.MemberOf_EquipmentContainer rdf:resource="#CIRSEC_510100016205211"/>
<cim:ACLineSegment.MemberOf_SegmentGroup rdf:resource="#SEGGRP_510030100811002"/>
</cim:ACLineSegment>
代码如下:(只是一部分。现在存在的问题是,这个解析方法解析的每个表里面的内容的顺序是不一样的,比如每次进这个条件之后if (subject.contains("SEG_")) { 下面的内容每次的顺序不一样,并且我xml文件里面主语下面的谓语的个数不一定相同,所以我没办法确定这一个seg走完了没有。 还是说我存储方法错误,有什么简单的方法?
public List<Map<String, Object>> GISInfo() {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
// String inputFileName = "F:\\javaSoftWare\\光纤入户\\RDF\\10kV新迎北线.xml";
String inputFileName = GISInfofileroot;
Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
model.read(in, "", "RDF/XML");//根据文件格式选用参数即可解析不同类型
System.out.println("开始");
// list the statements in the graph
StmtIterator iter = model.listStatements();
insetACLINESEGMENT(iter);
if (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
String subject = stmt.getSubject().toString(); // get the subject
String predicate = stmt.getPredicate().toString(); // get the predicate
RDFNode object = stmt.getObject(); // get the object
// LOG.debug(subject);
List<Map<String, Object>> resultIDS = getGISInfo(subject.split("#")[1].toString());
if (resultIDS.get(0).get("SUM").toString().equals("1")) {
isExist = 1;
} else {
if (subject.contains("SEG_")) {
//拼接sql语句,插入数据库
id = subject.toString().split("#")[1];
if (predicate.contains("IdentifiedObject.name")) {
name = object.toString();
flownum++;
} else if (predicate.contains("IdentifiedObject.mRID")) {
mrid = object.toString();
flownum++;
} else if (predicate.contains("PowerSystemResource.status")) {
status = object.toString();
flownum++;
} else if (predicate.contains("PowerSystemResource.maintainDepart")) {
maintain = object.toString();
flownum++;
} else if (predicate.contains("Equipment.model")) {
eqmodel = object.toString();
flownum++;
} else if (predicate.contains("ConductingEquipment.phases")) {
phases = object.toString();
flownum++;
} else if (predicate.contains("Conductor.length")) {
length = Double.parseDouble(object.toString());
flownum++;
} else if (predicate.contains("ACLineSegment.prevPSRID")) {
previd = object.toString();
flownum++;
} else if (predicate.contains("ACLineSegment.nextPSRID")) {
nextid = object.toString();
flownum++;
} else if (predicate.contains("PowerSystemResource.location")) {
location = object.toString();
flownum++;
} else if (predicate.contains("PowerSystemResource.PSRType")) {//1
psrtype = object.toString().split("#")[1];
flownum++;
} else if (predicate.contains("PowerSystemResource.BaseVoltage")) {
basevol = object.toString().split("#")[1];
flownum++;
} else if (predicate.contains("Equipment.MemberOf_EquipmentContainer")) {
equip = object.toString().split("#")[1];
flownum++;
} else if (predicate.contains("ACLineSegment.MemberOf_SegmentGroup")) {
sg = object.toString().split("#")[1];
flownum++;
}
if (flownum == 14) {
Object[] params;
int[] types;
String querySQL3 = "insert into GIS_ACLINESEGMENT(ID, NAME, MRID, STATUS, MAINTAINDEPART, MODEL, PHASES, LENGTH,"
+ " PREVPSRID, NEXTPSRID, LOCATION, PSRTYPE, BASEVOLTAGE, EQUIPMENTCONTAINER, SEGMENTGROUP)"
+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
params = new Object[]{id, name, mrid, status, maintain, eqmodel, phases, length, previd, nextid, location, psrtype, basevol, equip, sg};
types = new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.DOUBLE, Types.VARCHAR,
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR};
LOG.debug(querySQL3);
List<Map<String, Object>> resultIDSs = getGISInfo(id);
if (resultIDS.get(0).get("SUM").toString().equals("1")) {
LOG.debug("数据库中已存在此数据!!!");
flownum = 0;
} else {
int row_add3 = jdbcTemplate.update(querySQL3, params, types);
flownum = 0;
}
}
}