Commit 56176fbd by chengzhuoshen

修复xpath代码

parent 4c384059
...@@ -26,6 +26,7 @@ import javax.xml.datatype.XMLGregorianCalendar; ...@@ -26,6 +26,7 @@ import javax.xml.datatype.XMLGregorianCalendar;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.*; import java.util.*;
public abstract class AbstractMx2MtCreator implements Mx2MtCreator { public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
...@@ -197,7 +198,9 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator { ...@@ -197,7 +198,9 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
try { try {
String[] paths = path.split("\\."); String[] paths = path.split("\\.");
SAXReader saxReader = new SAXReader(); SAXReader saxReader = new SAXReader();
Document document = saxReader.read(AbstractMx2MtCreator.class.getResource("/xsd/"+xsdName+".xsd")); URL resource = AbstractMx2MtCreator.class.getResource("/xsd/" + xsdName + ".xsd");
if (resource == null) return false;
Document document = saxReader.read(resource);
Element element = document.getRootElement(); Element element = document.getRootElement();
String minOccurs = null; String minOccurs = null;
for (int i=0; i<paths.length; i++) { for (int i=0; i<paths.length; i++) {
...@@ -205,7 +208,10 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator { ...@@ -205,7 +208,10 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
if (p.indexOf("@") > -1) { if (p.indexOf("@") > -1) {
p = p.substring(0, p.indexOf("@")); p = p.substring(0, p.indexOf("@"));
} }
List<Node> nodeList = element.selectNodes("//xs:element[@name='"+p+"']"); if (p.indexOf("(") > -1) {
p = p.substring(0, p.indexOf("("));
}
List<Node> nodeList = element.selectNodes(".//xs:element[@name='"+p+"']");
if (nodeList == null || nodeList.size() == 0) { if (nodeList == null || nodeList.size() == 0) {
continue; continue;
} }
...@@ -215,7 +221,9 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator { ...@@ -215,7 +221,9 @@ public abstract class AbstractMx2MtCreator implements Mx2MtCreator {
} else { } else {
String type = element.attributeValue("type"); String type = element.attributeValue("type");
nodeList = element.selectNodes("//xs:complexType[@name='"+type+"']"); nodeList = element.selectNodes("//xs:complexType[@name='"+type+"']");
element = (Element) nodeList.get(0); if (nodeList != null && nodeList.size() > 0) {
element = (Element) nodeList.get(0);
}
} }
} }
if (minOccurs == null || Integer.parseInt(minOccurs) > 0) { if (minOccurs == null || Integer.parseInt(minOccurs) > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment