我正在尝试使用 SAXParser 从下面显示的 xml 中的元素“UserDetails”中获取编码字符。我只能获得长度为 126 的前2 行编码字符。我无法获得所有编码字符。检索这些字符的任何想法。
**User.xml**
<UserStatus>FALSE</UserStatus>
<UserDetails>
**AAAAAAAA//8BAAAAAAAAAAEAAQAAAP///f///wAAAQAAAAAAAgABAAIAAQAAAAAA//8CAAAAAAABAP////8A
AAAA//8AAP////8AAAAA/////wAA//////3//f/9//7//v/9/wAA/f/8//z//P/8//3//v/+//7//P/9//3/**
/P/7//r/+//8//v/+//6//r/+//5//n//P/6//r//P/6//n/+P/6//r/+v/6//r/+v/7//z//P/5//r/+v/7
//r/+f/5//r/+v/5//r/+f/5//r/+//6//n/9//3//n/+f/5//j/9//5//n/+P/5//n/+f/6//f/+P/4//f/
+P/5//j/+f/6//f/9v/2//f/9//3//n/+v/4//n/+f/3//b/9//4//n/9//4//b/9//0//f/9v/3//b/9//2
//T/9f/5//T/9f/2//X/9P/2//b/9v/0//T/8//2//T/9P/0//X/9v/1//f/9P/0//L/8v/y//L/9v/3//b/
9v/2//f/9v/1//X/9f/1//T/9v/3//X/9f/1//b/9v/2//b/9//3//n/9//1//T/8//1//b/9v/3//n/9//1
//T/9P/0//X/9v/0//b/9v/3//b/9v/1//P/9P/1//f/9//2//n/9//3//b/9//3//f/9//4//f/+f/3//b/
9v/0//X/9v/5//n/9//6//f/9//4//f/9//4//j/9//5//n/+f/2//X/9//0//T/9f/2//j/9v/4//b/9f/1
//T/9f/1//f/9v/3//X/9v/2//b/9f/1//T/9f/5//j/+P/4//n/+P/3//b/+P/4//f/9//2//j/+f/2//b/
</UserDetails>
<UserStatus>TRUE</UserStatus>
<UserDetails>
**AAAAAAAA//8BAAAAAAAAAAEAAQAAAP///f///wAAAQAAAAAAAgABAAIAAQAAAAAA//8CAAAAAAABAP////8A
AAAA//8AAP////8AAAAA/////wAA//////3//f/9//7//v/9/wAA/f/8//z//P/8//3//v/+//7//P/9//3/**
/P/7//r/+//8//v/+//6//r/+//5//n//P/6//r//P/6//n/+P/6//r/+v/6//r/+v/7//z//P/5//r/+v/7
//r/+f/5//r/+v/5//r/+f/5//r/+//6//n/9//3//n/+f/5//j/9//5//n/+P/5//n/+f/6//f/+P/4//f/
+P/5//j/+f/6//f/9v/2//f/9//3//n/+v/4//n/+f/3//b/9//4//n/9//4//b/9//0//f/9v/3//b/9//2
//T/9f/5//T/9f/2//X/9P/2//b/9v/0//T/8//2//T/9P/0//X/9v/1//f/9P/0//L/8v/y//L/9v/3//b/
9v/2//f/9v/1//X/9f/1//T/9v/3//X/9f/1//b/9v/2//b/9//3//n/9//1//T/8//1//b/9v/3//n/9//1
//T/9P/0//X/9v/0//b/9v/3//b/9v/1//P/9P/1//f/9//2//n/9//3//b/9//3//f/9//4//f/+f/3//b/
9v/0//X/9v/5//n/9//6//f/9//4//f/9//4//j/9//5//n/+f/2//X/9//0//T/9f/2//j/9v/4//b/9f/1
//T/9f/1//f/9v/3//X/9v/2//b/9f/1//T/9f/5//j/+P/4//n/+P/3//b/+P/4//f/9//2//j/+f/2//b/
</UserDetails>
**UserDetails.java**
import java.io.File;
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;
public class UserDetails {
public static void main(String args[]){
File file = new File("C:/user_records/User.xml");
final StringBuffer curCharValue = new StringBuffer(1024);
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
String sd = "";
String createdStr = "";
boolean stat= false;
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
curCharValue.setLength(0);
System.out.println("Start Element :" + qName);
if (qName.equalsIgnoreCase("UserDetails")) {
stat= true;
}
}
public void endElement(String uri, String localName,
String qName) throws SAXException {
System.out.println("End Element : " + qName);
}
public void characters(char ch[], int start, int length)
throws SAXException {
if (stat) {
System.out.println("User Details are : "
+ new String(ch, start, length));
curCharValue.append(ch, start, length);
byte[] decoded = Base64.decodeBase64(new String(
curCharValue));
System.out.println(decoded.length
+ " is decoded length");
for (int i = 0; i < decoded.length; i++) {
createdStr = decoded[i] + "";
if (createdStr.equals("-")
|| i == (decoded.length - 1)) {
sd += decoded[i];
} else {
sd += decoded[i] + ",";
}
}
System.out.println("the actual user details are : "
+ sd);
stat= false;
}
}
};
saxParser.parse(file, handler);
} catch (Exception e) {
e.printStackTrace();
}
}
}