<person>
<firstname>
<lastname>
<salary>
</person>
Run Code Online (Sandbox Code Playgroud)
这是我正在解析的XML.当我尝试打印人的子元素的节点名称时,我得到了
文本名字
文本姓
文本薪水
如何消除正在生成的#text?
更新 - 这是我的代码
try {
NodeList nl = null;
int l, i = 0;
File fXmlFile = new File("file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dbFactory.setValidating(false);
dbFactory.setIgnoringElementContentWhitespace(true);
dbFactory.setNamespaceAware(true);
dbFactory.setIgnoringComments(true);
dbFactory.setCoalescing(true);
InputStream in;
in = new FileInputStream(fXmlFile);
Document doc = dBuilder.parse(in);
doc.getDocumentElement().normalize();
Node n = doc.getDocumentElement();
System.out.println(dbFactory.isIgnoringElementContentWhitespace());
System.out.println(n);
if (n != null && n.hasChildNodes()) {
nl = n.getChildNodes();
for (i = 0; i < nl.getLength(); i++) …Run Code Online (Sandbox Code Playgroud) 我今天遇到了这个问题。我已将时钟设置为 UTC-6.00(中美洲)时区。我正在将日期“06/01/2015::12:00:00 AM”(“MM/dd/yyyy::hh:mm:ss a”格式)转换为 java Date 对象。然后我将日期对象重新转换为字符串。不过,我的做法略有不同。我在下面列出了重新转换步骤 -
我看到现在呈现的时间是“06/01/2015::01:00:00 AM”
我的问题:
由于时区偏移在创建和转换期间是相同的,我希望显示相同的时间。但我看到的是不同的。为什么会这样呢?
想象一下重新转换发生在服务器中,创建发生在客户端中。我需要向客户端返回相同的日期和时间。我该怎么做呢?
请帮忙!任何帮助深表感谢。
编辑:以下是代码。请注意,我已将当前时区设置为中美洲。
public class TimeTest {
public static void main (String args[]) {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy::hh:mm:ss a");
String dateInString = "01/06/2015::12:00:00 AM";
try {
Date date = formatter.parse(dateInString);
System.out.println("Before conversion --> " + formatter.format(date));
System.out.println("After conversion --> " + convertDateValueIntoString(date));
} catch (ParseException e) {
e.printStackTrace();
}
}
private static String convertDateValueIntoString(Date dateValue){
SimpleDateFormat …Run Code Online (Sandbox Code Playgroud)