我有一个输出,我将其转换为XML,但XML出现时有些标签不合适或错过了。
这是Ilog输出:
Y = [[[7.5
7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5]
[9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6]
[8.8889 8.8889 8.8889 8.8889 8.8889 8.8889 8.8889 8.8889 8.8889
8.8889 8.8889 8.8889 8.8889 8.8889 8.8889]
[8.2759 8.2759 8.2759 8.2759 8.2759 8.2759 8.2759 8.2759 8.2759
8.2759 8.2759 8.2759 8.2759 8.2759 8.2759]]
[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]];
X = [[[7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5 7.5]
[9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6 9.6]
[8.8889 8.8889 8.8889 8.8889 8.8889 8.8889 8.8889 8.8889 8.8889
8.8889 8.8889 8.8889 8.8889 8.8889 8.8889]
[8.2759 8.2759 8.2759 8.2759 8.2759 8.2759 8.2759 8.2759 8.2759
8.2759 8.2759 8.2759 8.2759 8.2759 8.2759]]
[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]];
XML输出:
<?xml version="1.0" encoding="UTF-8"?>
<Solutions>
<output_quantity>
<Y/> <--- one of the problem's
<Y>7.5<Y/>
<Y>7.5</Y><--- the other problem
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
<Y>7.5</Y>
</output_quantity>
<output_quantity>
<Y/>
<Y>9.6</Y>
<Y>9.6</Y>
<Y>9.6</Y>
<Y>9.6</Y>
<Y>9.6</Y>
这是我的代码:
public void process(String s) throws SAXException {
String[] elements = s.split("");
int flag = 0, flag2 = 0;
atts.clear();
if (s.contains("Y = ") || Y == 1) {
if (Y == 0) {
Y++;
th.startElement("", "", "Solutions", atts);
th.startElement("", "", "output_quantity", atts);
}
for (int i = 0; i < elements.length; i++) {
if (elements[i].equals(" ") && flag == 1 && flag2 == 1
|| elements[i].equals("]")) {
flag = 0;
if (flag2 == 1) {
th.endElement("", "", "Y");
if (elements[i].equals("]")) {
th.endElement("", "", "output_quantity");
th.startElement("", "", "output_quantity", atts);
}
}
flag2 = 0;
}
if (!elements[i].equals("[") && !elements[i].equals("Y")
&& !elements[i].equals("=") && !elements[i].equals(" ")
&& !elements[i].equals("]") && !elements[i].equals(";")) {
if (flag == 0)
th.startElement("", "", "Y", atts);
// Y++;
flag = 1;
flag2 = 1;
th.characters(elements[i].toCharArray(), 0,
elements[i].length());
// System.out.println("Information " + elements[i]);
}
}
if (s.contains("]]];")) {
// Y++;
th.endElement("", "", "output_quantity");
// th.endElement("", "", "Solutions");
}
}
有没有办法删除这些标签并纠正错位的“/”? 此致