我正在尝试解析一些XML并填充一篇博客帖子。我有解析位工作(至少当我所做的是将它们打印到屏幕时)。但是当我尝试使用正确的setter方法设置一个带有值的类变量,然后将该完整对象推送到我的列表时,我得到了一大堆空值。我已经尝试了所有我能想到的东西,因此希望获得潜伏在这里的专业知识。
有很多代码,所以我把它发布到这里:
非常感谢我出错的地方。
非常感谢
答案 0 :(得分:1)
你需要在这里使用调试器 - 我快速将一个BlogPost类放在一起进行测试,我发现你的代码正在为每个节点单独创建一个BlogPost - 所以<rss>
创建一个空白的BlogPost,就像{ {1}},<channel>
等。
我没有太多使用SAX Parsers(或者这种深度的XML解析),但我认为你只需要在<atom:link>
方法中创建BlogPosts。
答案 1 :(得分:0)
我已经稍微修改了你的代码,我没有错误:
Blog array size is 1
Blog array size is 2
Blog array size is 3
Blog array size is 4
Blog array size is 5
Blog array size is 6
Blog array size is 7
Blog array size is 8
Blog array size is 9
Blog array size is 10
Blog array size is 11
Blog array size is 12
Blog array size is 13
Blog array size is 14
Blog array size is 15
Blog array size is 16
Blog array size is 17
Blog array size is 18
Blog array size is 19
Blog array size is 20
Blog array size is 21
Blog array size is 22
Blog array size is 23
Blog array size is 24
Blog array size is 25
Blog array size is 26
Blog array size is 27
Blog array size is 28
Blog array size is 29
Blog array size is 30
Blog array size is 31
Blog array size is 32
Blog array size is 33
Blog array size is 34
Blog array size is 35
Blog array size is 36
Blog array size is 37
Blog array size is 38
Blog array size is 39
Blog array size is 40
Blog array size is 41
Blog array size is 42
Blog array size is 43
Blog array size is 44
Blog array size is 45
Blog array size is 46
Blog array size is 47
Blog array size is 48
Blog array size is 49
Blog array size is 50
Blog array size is 51
Blog array size is 52
Blog array size is 53
Blog array size is 54
Blog array size is 55
Blog array size is 56
Blog array size is 57
Blog array size is 58
Blog array size is 59
Blog array size is 60
Blog array size is 61
Blog array size is 62
Blog array size is 63
Blog array size is 64
Blog array size is 65
Blog array size is 66
Blog array size is 67
Blog array size is 68
Blog array size is 69
Blog array size is 70
Blog array size is 71
Blog array size is 72
Blog array size is 73
Blog array size is 74
Blog array size is 75
Blog array size is 76
Blog array size is 77
Blog array size is 78
Blog array size is 79
Blog array size is 80
Blog array size is 81
Blog array size is 82
Blog array size is 83
Blog array size is 84
Blog array size is 85
Blog array size is 86
Blog array size is 87
Blog array size is 88
Blog array size is 89
Blog array size is 90
Blog array size is 91
Blog array size is 92
Blog array size is 93
Blog array size is 94
Blog array size is 95
Blog array size is 96
Blog array size is 97
Blog array size is 98
Blog array size is 99
Blog array size is 100
Blog array size is 101
Blog array size is 102
Blog array size is 103
Blog array size is 104
Blog array size is 105
Blog array size is 106
Blog array size is 107
Blog array size is 108
Blog array size is 109
Blog array size is 110
Blog array size is 111
Blog array size is 112
Blog array size is 113
Blog array size is 114
Blog array size is 115
Blog array size is 116
Blog array size is 117
Blog array size is 118
Blog array size is 119
Blog array size is 120
Blog array size is 121
Blog array size is 122
Blog array size is 123
Blog array size is 124
Blog array size is 125
Blog array size is 126
Blog array size is 127
Blog array size is 128
Blog array size is 129
Blog array size is 130
Blog array size is 131
Blog array size is 132
Blog array size is 133
Blog array size is 134
Blog array size is 135
Blog array size is 136
Blog array size is 137
Blog array size is 138
Blog array size is 139
Blog array size is 140
Blog array size is 141
Blog array size is 142
Blog array size is 143
Blog array size is 144
Blog array size is 145
Blog array size is 146
Blog array size is 147
Blog array size is 148
Blog array size is 149
Blog array size is 150
Blog array size is 151
Blog array size is 152
Blog array size is 153
Blog array size is 154
Blog array size is 155
Blog array size is 156
Blog array size is 157
Blog array size is 158
Blog array size is 159
Blog array size is 160
Blog array size is 161
Blog array size is 162
Blog array size is 163
Blog array size is 164
Blog array size is 165
Blog array size is 166
Blog array size is 167
Blog array size is 168
Blog array size is 169
Blog array size is 170
Blog array size is 171
Blog array size is 172
Blog array size is 173
Blog array size is 174
Blog array size is 175
Blog array size is 176
Blog array size is 177
Blog array size is 178
Blog array size is 179
Blog array size is 180
Blog array size is 181
Blog array size is 182
Blog array size is 183
Blog array size is 184
Blog array size is 185
Blog array size is 186
Blog array size is 187
Blog array size is 188
Blog array size is 189
Blog array size is 190
Blog array size is 191
Blog array size is 192
Blog array size is 193
Blog array size is 194
Blog array size is 195
Blog array size is 196
Blog array size is 197
Blog array size is 198
Blog array size is 199
Blog array size is 200
Blog array size is 201
Blog array size is 202
Blog array size is 203
Blog array size is 204
Blog array size is 205
Blog array size is 206
Blog array size is 207
Blog array size is 208
Blog array size is 209
Blog array size is 210
Blog array size is 211
Blog array size is 212
Blog array size is 213
Blog array size is 214
Blog array size is 215
Blog array size is 216
Blog array size is 217
Blog array size is 218
Blog array size is 219
Blog array size is 220
Blog array size is 221
Blog array size is 222
Blog array size is 223
Blog array size is 224
Blog array size is 225
Blog array size is 226
Blog array size is 227
Blog array size is 228
Blog array size is 229
Blog array size is 230
Blog array size is 231
Blog array size is 232
Blog array size is 233
Blog array size is 234
Blog array size is 235
Blog array size is 236
Blog array size is 237
Blog array size is 238
Blog array size is 239
Blog array size is 240
Blog array size is 241
Blog array size is 242
Blog array size is 243
Blog array size is 244
Blog array size is 245
Blog array size is 246
Blog array size is 247
Blog array size is 248
Blog array size is 249
Blog array size is 250
Blog array size is 251
Blog array size is 252
Blog array size is 253
Blog array size is 254
Blog array size is 255
Blog array size is 256
Blog array size is 257
Blog array size is 258
Blog array size is 259
Blog array size is 260
Blog array size is 261
Blog array size is 262
Blog array size is 263
Blog array size is 264
Blog array size is 265
Blog array size is 266
Blog array size is 267
Blog array size is 268
Blog array size is 269
Blog array size is 270
Blog array size is 271
Blog array size is 272
Blog array size is 273
Blog array size is 274
Blog array size is 275
Blog array size is 276
Blog array size is 277
Blog array size is 278
Blog array size is 279
Blog array size is 280
Blog array size is 281
Blog array size is 282
Blog array size is 283
Blog array size is 284
Blog array size is 285
Blog array size is 286
Blog array size is 287
Blog array size is 288
Blog array size is 289
Blog array size is 290
Blog array size is 291
Blog array size is 292
Blog array size is 293
Blog array size is 294
Blog array size is 295
Blog array size is 296
Blog array size is 297
Blog array size is 298
Blog array size is 299
Blog array size is 300
Blog array size is 301
Blog array size is 302
Blog array size is 303
Blog array size is 304
Blog array size is 305
Blog array size is 306
Blog array size is 307
Blog array size is 308
Blog array size is 309
Blog array size is 310
Blog array size is 311
Blog array size is 312
Blog array size is 313
我做的修改是将xml从http://onthehilluk.wordpress.com/feed/复制到本地文件中,并使用:parser.parse(new File("c:\\test\\feed.xml"), handler);
而不是parser.parse(url, handler);
引用该文件。我做出此更改的原因是我从防火墙后面运行代码,所以我无法从java类下载xml。确保您不在防火墙后面。您还应该发布程序的输出。如果您使用我所做的修改来运行代码,请确保第一行xml文件不为空,因为如果它是(空),您将收到org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
。