XML解析错误:Xquery中文档元素之后的垃圾

时间:2012-02-01 16:37:20

标签: xml xpath xquery exist-db

嘿,我是使用eXist和Xquery的新手。

这是我的问题。我尝试使用xQuery从xml文件(存储在eXist数据库中)中检索一些数据。当我只是在没有任何条件的情况下进行检索时它会变好。 当我使用某些条件时,它会给我这个错误:

  

XML解析错误:文档元素之后的垃圾

这是xml文件:

<?xml version="1.0" ?>
<produk>
    <prod_detail>
        <prod_name>Spreadrum G189</prod_name>
        <struc>PDA</struc>
        <company_org>pti</company_org>
    </prod_detail>
    <hard_spec>
        <chipset>SC6800H</chipset>
        <comm>
            <sim_mode>
                <single></single>
                <dual></dual>
            </sim_mode>
            <netw_freq>EGSM900/DCS1800</netw_freq>
            <gprs></gprs>
            <voice_encode></voice_encode>
        </comm>
        <disp>
            <lcd_info>3.5 HVGA 320*480</lcd_info>
            <back_light>0</back_light>
            <touch_scr>1</touch_scr>
            <vice_scr>0</vice_scr>
            <tp_conn>welded</tp_conn>
            <com_ipcall_disp>1</com_ipcall_disp>
        </disp>
        <cam>
            <cam_pos>
                <front_cam>1</front_cam>
                <back_cam>1</back_cam>
            </cam_pos>
            <cam_pix>
                <front_cam>0.3Mp</front_cam>
                <back_cam>2Mp</back_cam>
            </cam_pix>
            <cam_chip>CMOS</cam_chip>
            <flash>1</flash> 
            <cam_con>Welded</cam_con>
        </cam>
        <pcb_size> </pcb_size>
        <sound>
            <speaker>class D (1524)</speaker>
            <player>yes</player>
        </sound>
        <store>
            <memory_capacity>1G+256M</memory_capacity>
            <mem_card>1</mem_card>
        </store>
        <data_trans>
            <USB>1</USB>
            <infrared>0</infrared>
            <bluetooth>1</bluetooth>
            <wifi></wifi> 
        </data_trans>
        <mult>
            <fm>1</fm>
            <tv>0</tv>
            <gps>0</gps>
        </mult>
        <butt>  
            <keypad>
                <qwerty>0</qwerty>
                <func_key>5</func_key>
                <num_key>0</num_key>
                <side_key>volume and camera key (FPC)</side_key>
                <key_ext></key_ext>
                <color_key>white</color_key>
            </keypad>
            <touch_key>0</touch_key>
            <trackball>0</trackball>
            <opt_mouse>0</opt_mouse>
            <led>0</led>
        </butt>  
        <ui>
            <connect_sim>rangkap 3</connect_sim>
            <ext_deck>TF socket card</ext_deck>
            <rf_test_port>no</rf_test_port>
            <intfc_io>micro 5 pin usb</intfc_io>
            <headphone_jack>micro 5 pin usb</headphone_jack>
            <charging_ui>micro 5 pin usb</charging_ui>
            <ui_usb>micro 5 pin usb</ui_usb>
            <speed_touch>0</speed_touch>
        </ui>
        <other>
            <batt>900mAh</batt>
            <antenna>PIFA</antenna>
            <torch>0</torch>
        </other>

    </hard_spec>

    <soft_spec>
        <style>android iphone</style>
        <comm>  
            <sim_vas>1</sim_vas>
            <data_con>
                <gprs>1</gprs>
                <wap>1</wap>
            </data_con>
            <message>
                <sms>
                    <swr>1</swr>
                    <sin>1</sin>
                    <sout>1</sout>
                    <sdrf>1</sdrf>
                    <ssent>1</ssent>
                </sms>
                <mms>
                    <mwr>1</mwr>
                    <min>1</min>
                    <mout>1</mout>
                    <mdrf>1</mdrf>
                    <msent>1</msent> 
                    <group_mms>1</group_mms>
                    <mms_chat_room>1</mms_chat_room>
                    <comm_bm>1</comm_bm>
                </mms>
                <email>
                    <esent>0</esent>
                    <erecv>0</erecv>
                    <ein>0</ein>
                    <eout>0</eout>
                    <esent>0</esent> 
                    <edrft>0</edrft>
                    <eact>0</eact>
                </email>
            </message>
            <phone_book>
                <capacity>500</capacity>
                <search_con>1</search_con>
                <add>1</add>
                <save>1</save>
                <dial>1</dial>
                <grup_num>1</grup_num>
                <captive_chk>1</captive_chk>
            </phone_book>
            <call>
                <sim_hist>
                    <sim1>1</sim1>
                    <sim2>1</sim2>
                </sim_hist>
                <dial_up_ip>1</dial_up_ip>
                <call_grup>0</call_grup>
                <set_call_id>0</set_call_id>
                <call_div>1</call_div>
                <call_bar>1</call_bar>
                <call_hold>1</call_hold>
                <call_redial>1</call_redial>
                <call_fee>1</call_fee>
                <handsfree>1</handsfree>
                <cdial>1</cdial>
                <crecv>1</crecv>
                <call_rec></call_rec>
            </call>
        </comm>
        <multimedia>
            <cam>
                <sw_cam>1</sw_cam>
                <sub_cam>1</sub_cam>
                <main_cam>1</main_cam>
                <capt>1</capt>
                <zoom>1</zoom>
                <contras>1</contras>
                <save>1</save>
                <flash>0</flash>
                <set_to_wpp>1</set_to_wpp>
                <view_pic>1</view_pic>
                <wb_conf>1</wb_conf>
                <cont_photo>1</cont_photo>
                <exposure_comp>1</exposure_comp>
                <effect_set>1</effect_set>
            </cam>
            <video>
                <vid_form>
                    <mp4>1</mp4>
                    <trigp>1</trigp>
                    <avi>1</avi>
                    <rmvb>1</rmvb>
                    <king_mov>1</king_mov>
                </vid_form>
                <vid_rec>1</vid_rec>
                <sw_cam>1</sw_cam>
                <vid_fcam>0</vid_fcam>
                <vid_rcam>1</vid_rcam>
                <vid_zoom>1</vid_zoom>
                <contras>1</contras>
                <save>
                    <phone>1</phone>
                    <mmc>1</mmc>
                </save>
                <vid_play>1</vid_play>
                <vid_disp>1</vid_disp>
                <adj_vol>1</adj_vol>
                <add_vid>
                    <from_card>1</from_card>
                    <from_phone>1</from_phone>
                </add_vid>
                <vid_app>1</vid_app>
            </video>
            <audio>
                <aud_form>
                    <mp3>1</mp3>
                    <wav>1</wav>
                    <midi>1</midi>
                </aud_form>
                <play>1</play>
                <playlist>1</playlist>
                <play_sett>1</play_sett>
                <back_sound>1</back_sound>
                <btooth_aud_out>0</btooth_aud_out>
                <adj_vol>1</adj_vol>
                <add>
                        <from_card>1</from_card>
                        <from_phone>1</from_phone>
                    </add>
                <radio>1</radio>
                <radio_menu>
                    <rad_play>1</rad_play>
                    <adj_vol>1</adj_vol>
                    <select_feq>1</select_feq>
                    <save_freq>0</save_freq>
                    <search_freq>1</search_freq>
                    <record>0</record>
                    <save>
                        <card>0</card>
                        <phone>0</phone>
                    </save>
                </radio_menu>
                <sound_rec>1</sound_rec>
                <sound_rec_menu>
                    <record>1</record>
                    <play>1</play>
                    <save>
                        <card>1</card>
                        <phone>1</phone>
                    </save>
                </sound_rec_menu>                   
            </audio>
            <imaging>
                <im_viewer>1</im_viewer>
                <im_viewer_menu>
                    <rotate>1</rotate>
                    <zoom>1</zoom>
                    <slide>1</slide>
                    <set_wpp>1</set_wpp>
                    <send>1
                        <via_btooth>1</via_btooth>
                        <via_mms>1</via_mms>
                    </send>
                    <edit>1</edit>
                    <detail>1</detail>
                </im_viewer_menu>
                <photo_editor>1</photo_editor>
                <photo_editor_menu>
                    <auto_resize>0</auto_resize>
                </photo_editor_menu>
            </imaging>
            <another_mfunc>
                <tv>1</tv>
                <games>1</games>
                <gps>0</gps>
                <keypad_lock>1</keypad_lock>
            </another_mfunc>
        </multimedia>
        <service>
            <sim_serv>
                <stk_sim_1>1</stk_sim_1>
                <stk_sim_2>1</stk_sim_2>
                <browsing>1</browsing>
            </sim_serv>
            <chat>1</chat>
            <java>0</java>
            <opera>0</opera>
            <m_offc>0</m_offc>
            <fb_sc>0</fb_sc>
            <pimo_sc>0</pimo_sc>
            <tpulsa_sc>0</tpulsa_sc>
        </service>
        <tools>
            <btooth>
                <on_off>1</on_off>
                <send>1</send>
                <recv>1</recv>
                <a2dp>0</a2dp>
            </btooth>
            <cald>1</cald>
            <calc>1</calc>
            <task>0</task>
            <alarm>1</alarm>
            <w_clock>1</w_clock>
            <u_convrt>1</u_convrt>
            <curr_conv>1</curr_conv>
            <health_man>1</health_man>
            <ebook_read>1</ebook_read>
            <swatch>0</swatch>
            <notes>1</notes>
            <code_table>1</code_table>
            <updownload_pbook>0</updownload_pbook>
            <usr_prof>1</usr_prof>
            <handwritting>1</handwritting>
        </tools>
        <sett>
            <file_man>
                <int_mem>1</int_mem>
                <ext_mem>1</ext_mem>
                <rwmrmov>1</rwmrmov>
                <format>1</format>
            </file_man>
            <disp>
                <wpp>1</wpp>
                <ssaver>1</ssaver>
                <pon_disp>1</pon_disp>
                <poff_disp>1</poff_disp>
                <show_own_num>0</show_own_num>
            </disp>
            <p_sett>
                <sch_pow_on>1</sch_pow_on>
                <in_lang>
                    <eng>1</eng> 
                    <stroke>1</stroke>
                    <piyin>1</piyin>
                    <french>0</french>
                    <german>0</german>
                    <spain>0</spain>
                    <russian>0</russian>
                    <indonesian>1</indonesian>
                    <portugis>0</portugis>
                    <turkish>0</turkish>
                    <persian>0</persian>
                    <italia>0</italia>
                </in_lang>
                <lang>
                    <eng>1</eng>
                    <ind>0</ind>
                    <china>1</china>
                    <french>0</french>
                    <german>0</german>
                    <spain>0</spain>
                    <russian>0</russian>
                    <indonesian>0</indonesian>
                    <portugis>0</portugis>
                    <turkish>0</turkish>
                    <persian>0</persian>
                    <italia>0</italia>
                </lang>
                <time_date>1</time_date>
                <pref_in>0</pref_in>
                <greet_text>0</greet_text>
                <dedic_key>0</dedic_key>
                <auto_update_time>1</auto_update_time>
                <uart_sett>0</uart_sett>

            </p_sett>
            <s_oth>
                <sound_sett>1</sound_sett>
                <sound_sett_opt>
                    <aud_eff>1</aud_eff>
                    <bass_ench>0</bass_ench>
                </sound_sett_opt>
                <dual_sim_sw>0</dual_sim_sw>
                <dual_sim_sett>0</dual_sim_sett>
                <pen_call>0</pen_call>
                <netw_sett>0</netw_sett>
                <sec_sett>0</sec_sett>
                <rest_sett>0</rest_sett>
            </s_oth>
            <misc_sett>
                <sens_app>
                    <wall_shuff>0</wall_shuff>
                    <mp3_shuff>0</mp3_shuff>
                    <phone_shake>0</phone_shake>
                    <shake_to_read_sms>0</shake_to_read_sms>
                    <fm_chs_shake>0</fm_chs_shake>
                    <revrse_phone_mute>0</revrse_phone_mute>
                    <double_knock_mute>0</double_knock_mute>
                </sens_app>
                <voiceaid_sett>
                    <engin_sett>0</engin_sett>
                    <r_in_call>0</r_in_call>
                    <r_in_mess>0</r_in_mess>
                    <r_time_on_idle>0</r_time_on_idle>
                    <r_time_per_hour>0</r_time_per_hour>
                    <r_menu>0</r_menu>
                    <r_mesg>0</r_mesg>
                    <r_charge>0</r_charge>
                    <r_dial>0</r_dial>
                    <vol>0</vol>
                    <rate>0</rate>
                    <pith>0</pith>
                </voiceaid_sett>
                <wapp>
                    <wapp_form>
                        <gif>1</gif>
                        <bmp>1</bmp>
                        <jpg>1</jpg>
                    </wapp_form>
                    <wall_cust>1</wall_cust>
                    <dynamic_screensaver>0</dynamic_screensaver>
                </wapp>
            </misc_sett>
        </sett>

        <misc_func>
            <ani>
                <p_on_logo>1</p_on_logo>
                <p_off_logo>1</p_off_logo>
            </ani>
            <ring> 
                <default>1</default>
                <ring_form>
                    <mp3>1</mp3>
                    <midi>1</midi>
                    <wav>1</wav>
                </ring_form>
                <back_ring_for_call>1</back_ring_for_call>
                <ring_edit>1</ring_edit>
            </ring>
            <vib_feedback>
                <touch_scr>1</touch_scr>
                <dial_num>1</dial_num>
            </vib_feedback>
        </misc_func>
    </soft_spec>
</produk>

这是我的xql代码:

declare namespace xdb = "http://exist-db.org/xquery/xmldb";

for $x in doc("/db/skripsi/database/PTI/spreadrum_g189.xml")//*
where data($x)="1"
return $x

xql代码实际上在沙盒中工作得很好,但我不知道为什么它在实际实现时会给我错误:(。

2 个答案:

答案 0 :(得分:0)

我不知道如何重现您报告的问题,但如果您只在文档的文本节点上应用相等性测试,那么您的查询会更准确:

declare namespace xdb = "http://exist-db.org/xquery/xmldb";
for $x in doc("/db/skripsi/database/PTI/spreadrum_g189.xml")//*
where $x/text() = "1"
return $x

否则,data()函数将在文档的所有元素节点上执行(即使是那些具有更多后代节点的节点),这可能需要很长时间,如果处理过的数据也会导致错误大。

希望这有帮助, 基督教

答案 1 :(得分:0)

XML Parsing Error: junk after document element

这指向关闭文档节点之后的一些垃圾内容 - 在这种情况下是</produk>之后。 XML不允许文档节点之后的任何内容(expcept PIs, comments, whitespace)。在某些文本编辑器中打开内容,确保没有不需要的字符作为受保护的空白,BOM等。

我从您粘贴的文件中复制了整个XML内容,也很好。也许试着把它复制回来。