XSTREAM
当我有以下XML代码时:
<xml>
<version>1.1</version>
<url>http://www.google.nl</url>
</xml>
Run Code Online (Sandbox Code Playgroud)
我用我的Java代码读到这一切一切正常,但是当XML发生变化时,例如:
<xml>
<test>test</test>
<version>1.1</version>
<url>http://www.google.nl</url>
</xml>
Run Code Online (Sandbox Code Playgroud)
我收到错误,但我希望程序不会停止,并且不要使用现场测试.有没有办法处理这个异常而不停止程序?
Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldExce ption: No such field Version.iets
---- Debugging information ----
field : iets
class : Version
required-type : Version
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /Version/iets
line number : 1
version : null
-------------------------------
Run Code Online (Sandbox Code Playgroud) 我正在重用其他地方生成的现有对象来解组以String类型形式出现的XML数据.
物体:
/* 3: */ import java.util.ArrayList;
/* 4: */ import java.util.List;
/* 5: */ import javax.xml.bind.annotation.XmlAccessType;
/* 6: */ import javax.xml.bind.annotation.XmlAccessorType;
/* 7: */ import javax.xml.bind.annotation.XmlElement;
/* 8: */ import javax.xml.bind.annotation.XmlRootElement;
/* 9: */ import javax.xml.bind.annotation.XmlType;
/* 10: */
/* 11: */ @XmlAccessorType(XmlAccessType.FIELD)
/* 12: */ @XmlType(name="", propOrder={"policy"})
/* 13: */ @XmlRootElement(name="MyNodeResponse")
/* 14: */ public class MyNodeResponse
/* 15: */ {
/* 16: */ @XmlElement(name="Policy")
/* 17: */ protected List<Policy> policy;
/* 18: */
/* 19: */ public …Run Code Online (Sandbox Code Playgroud) 我已经浏览了许多有关此问题的类似标题的问题,并尝试了许多已接受的答案,但仍然得到不需要的行空间。像许多问题一样,我正在制作一个电子邮件模板,因此我必须使用嵌套表来不仅获得我想要的结构,而且使其能够在电子邮件中正确呈现。
我尝试过的解决方案均无效:
这些似乎都没有什么区别,我无法摆脱行空间。这种情况发生在 Chrome/IE/Firefox 中。

<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
Title
</title>
<style type="text/css">
a:hover { text-decoration: none !important; }
.header h1 {color: #055d90; font: normal 25px Georgia, Times, serif; margin: 0; font-weight: bold; padding: 0 0 0px 0; line-height: 39px; margin-top: 0;}
.header p {color: #cf373e; font: normal 17px Georgia, Times, serif; margin: 0; padding: 0; line-height: 12px; font-style: italic;}
.custinfo …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的xpath:
$path = '//*[@id="page-content"]/table/tbody/tr[3]/td['.$i.']/div/a';
Run Code Online (Sandbox Code Playgroud)
其中,$i从1到X.我会正常使用:
for($i=1; $i<X;$i++){
$path = '//*[@id="page-content"]/table/tbody/tr[3]/td['.$i.']/div/a';
$nodelist = $xpath->query($path);
$result = $nodelist->item(0)->nodeValue;
};
Run Code Online (Sandbox Code Playgroud)
但是,在这种情况下,我不知道X有多少.有没有办法在不知道X的情况下循环这个?
java ×2
xml ×2
css ×1
html ×1
html-email ×1
html-parsing ×1
jaxb ×1
namespaces ×1
php ×1
xpath ×1
xstream ×1