2010-10-20 214 views
0

我需要解析此:解析XML使用jQuery

<?xml version="1.0" encoding="utf-8"?> 
<blamatrixrix> 
<name></name> 
<columns number="2"> 
<column id="title" num="0">Title</column> 
<column id="content" num="1">Content</column> 
</columns> 
<rows number="7"></rows> 
<b>Description</c> 
<bDescription text here</b> 
<b>Some title 1</b> 
<b>Some text blabla for Some title 1</b> 
<b>Some title 2</b> 
<b>Some text blabla for Some title 2</b> 
<b>Some title 3</b> 
<b>Some text blabla for Some title 3</b> 
<b>Some title 4</b> 
<b>Some text blabla for Some title 4</b> 
<b>Some title 5</b> 
<b>Some text blabla for Some title 5</b> 
<b>Some title 6</b> 
<b>Some text blabla for Some title 6</b> 
</blamatrixrix> 

在某種程度上內容是在表中。而「有些標題」本身就是自己的,還有「某些文本」。

因爲裏面的內容是給我麻煩的。我應該以某種方式使用正則表達式嗎?

我得到的XML從這個:

$.getJSON(JSONquery, function(data){ 
    $.each(data, function(i,item){ 

編輯:

@利亞姆·貝利

這裏是JSONquery的代碼輸出:

[{"name":"139930 blablabla","id":599,"contentobject_id":599,"main_node_id":565,"modified":"1287146683","published":"1264417592","section_id":1,"current_language":"eng","owner_id":193,"class_id":28,"class_name":"Product","class_identifier":"product","is_container":0,"node_id":565,"parent_node_id":355,"url_alias":"Products\/blablabla\/blablabla\/139930-blablabla","depth":6,"path":false,"children_count":false,"image_attributes":["main_image","listing_thumbnail","promo_badge"],"data_map":{"title":{"id":"6488","type":"ezstring","identifier":"title","content":"blablabla"},"short_title":{"id":"6489","type":"ezstring","identifier":"short_title","content":"139930 blablabla"},"subtitle":{"id":"6490","type":"ezstring","identifier":"subtitle","content":""},"authors":{"id":"6491","type":"ezauthor","identifier":"authors","content":"blablabla blablabla | [email protected] blablabla .com|0"},"keywords":{"id":"6492","type":"ezkeyword","identifier":"keywords","content":"blablabla"},"item_id":{"id":"6493","type":"ezstring","identifier":"item_id","content":"139930"},"price":{"id":"6494","type":"ezprice","identifier":"price","content":"0|1|1"},"is_shoppable":{"id":"6495","type":"ezboolean","identifier":"is_shoppable","content":"0"},"main_image":{"id":"6496","type":"ezimage","identifier":"main_image","content":{"reference":false,"small":{"name":"small","width":"100","height":"33","mime_type":"image\/jpeg","filename":"139930-blablabla_small.jpg","suffix":"jpg","dirpath":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/lawn-blablabla\/blablabla\/139930-blablabla\/6496-25-eng-EU","alias_key":"2343348577","timestamp":"1286700665","is_valid":"1","url":"var\/blablabla\/storage\/images\/frontpage\/products\/blablabla-care\/blablabla\/139930-blablabla/6496-25-eng-EU\/139930-blablabla-blablablar_small.jpg","basename":"139930-blablabla-blablablar","alternative_text":"","text":"","original_filename":"139930_2.jpg","full_path":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/blab-bla\/blaaders\/139930-blablabla-blablablar\/6496-25-eng-EU\/139930-blablabla-blablablar_small.jpg","is_new":false,"info":{"Height":"200","Width":"600","IsColor":"1"}},"tiny":false,"medium":false,"large":false,"rss":false,"width100":false,"width150":false,"width200":false,"width300":false,"width400":false,"product_main":false,"product_main_large":false,"product_listing":false,"product_category_listing":false,"product_media_listing":false,"rc_full":false,"main_banner":false,"main_banner_front":false,"promo_badge":false,"multiuploadthumbnail":false,"original":{"url":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/blab-bla\/blaaders\/139930-blablabla-blablablar\/6496-25-eng-EU\/139930-blablabla-blablablar.jpg|"}}},"listing_thumbnail":{"id":"6497","type":"ezimage","identifier":"listing_thumbnail","content":{"reference":false,"small":null,"tiny":false,"medium":false,"large":false,"rss":false,"width100":false,"width150":false,"width200":false,"width300":false,"width400":false,"product_main":false,"product_main_large":false,"product_listing":false,"product_category_listing":false,"product_media_listing":false,"rc_full":false,"main_banner":false,"main_banner_front":false,"promo_badge":false,"multiuploadthumbnail":false,"original":{"url":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/blab-bla\/blaaders\/139930-blablabla-blablablar\/6497-25-eng-EU\/139930-blablabla-blablablar.jpg|"}}},"related_images":{"id":"6498","type":"ezobjectrelationbrowse","identifier":"related_images","content":"605"},"related_media":{"id":"6499","type":"ezobjectrelationbrowse","identifier":"related_media","content":""},"related_products":{"id":"6500","type":"ezobjectrelationbrowse","identifier":"related_products","content":""},"related_faq_items":{"id":"6501","type":"ezobjectrelationbrowse","identifier":"related_faq_items","content":""},"awards":{"id":"6502","type":"ezxmltext","identifier":"awards","content":"\n 
      \n"},"country_awards":{"id":"601924","type":"ezxmltext","identifier":"country_awards","content":"\n 


     \n"},"description":{"id":"6503","type":"ezxmltext","identifier":"description","content":"\n 
      blablabla<\/line><\/paragraph><\/section>\n"},"features":{"id":"6504","type":"ezxmltext","identifier":"features","content":"\n 
      • blablabla <\/paragraph><\/li> 
      • blablabla <\/paragraph><\/li> 
      • blablabla <\/paragraph><\/li> 
      • blablabla <\/paragraph><\/li> 
      • C blablabla <\/paragraph><\/li><\/ul><\/paragraph><\/section>\n"},"freeform_1_title":{"id":"6505","type":"ezstring","identifier":"freeform_1_title","content":""},"freeform_1_content":{"id":"6506","type":"ezxmltext","identifier":"freeform_1_content","content":"\n\n"},"freeform_2_title":{"id":"6507","type":"ezstring","identifier":"freeform_2_title","content":""},"freeform_2_content":{"id":"6508","type":"ezxmltext","identifier":"freeform_2_content","content":"\n\n"},"freeform_3_title":{"id":"6509","type":"ezstring","identifier":"freeform_3_title","content":""},"freeform_3_content":{"id":"6510","type":"ezxmltext","identifier":"freeform_3_content","content":"\n\n"},"promo_badge":{"id":"277833","type":"ezimage","identifier":"promo_badge","content":{"reference":false,"small":null,"tiny":false,"medium":false,"large":false,"rss":false,"width100":false,"width150":false,"width200":false,"width300":false,"width400":false,"product_main":false,"product_main_large":false,"product_listing":false,"product_category_listing":false,"product_media_listing":false,"rc_full":false,"main_banner":false,"main_banner_front":false,"promo_badge":false,"multiuploadthumbnail":false,"original":{"url":"|"}}},"weight":{"id":"433850","type":"ezstring","identifier":"weight","content":"1052"},"length":{"id":"433851","type":"ezstring","identifier":"length","content":"970"},"product_attributes":{"id":"691877","type":"blamatrix","identifier":"product_attributes","content":{"HTTPValue":null,"Content":null,"DisplayInfo":null,"IsValid":null,"ContentClassAttributeID":"891","ValidationError":null,"ValidationLog":null,"ContentClassAttributeIdentifier":"product_attributes","ContentClassAttributeCanTranslate":null,"ContentClassAttributeName":null,"ContentClassAttributeIsInformationCollector":null,"ContentClassAttributeIsRequired":null,"PersistentDataDirty":false,"InputParameters":false,"HasValidationError":false,"DataTypeCustom":null,"ID":"691877","ContentObjectID":"599","Version":"26","LanguageCode":"eng-EU","LanguageID":"8","AttributeOriginalID":"0","SortKeyInt":"0","SortKeyString":"","DataTypeString":"blamatrix","DataText":"\n<\/name>Title<\/column>Content<\/column><\/columns>Description<\/b><ul><li>I NEED THIS DESC TEXT<\/li><\/ul><\/b>SOME TITLE<\/b><ul><li>THIS TEXT<\/li><\/ul><\/b>THIS TITLE<\/b>THIS TEXT<\/b>THIS TITLE<\/b>AGAIN THIS TEXT<\/b>THIS TITLE<\/b><ul><li>THIS TEXAT<\/li><\/ul><\/b>THIS TITLE<\/b><ul><li>THIS TEXT<\/li><\/ul><\/b>YEP THIS TITLE<\/b>THIS<\/b><\/blamatrix>\n","DataInt":null,"DataFloat":"0"}}}}] 
+0

獲取JSON不應該返回XML,你能告訴我們JSONquery – 2010-10-20 13:11:00

+0

代碼中看到我的輸出代碼的答案。 – peter 2010-10-20 13:25:33

回答

0

@利亞姆·貝利

下面是JSONquery的代碼輸出:

[{"name":"139930 blablabla","id":599,"contentobject_id":599,"main_node_id":565,"modified":"1287146683","published":"1264417592","section_id":1,"current_language":"eng","owner_id":193,"class_id":28,"class_name":"Product","class_identifier":"product","is_container":0,"node_id":565,"parent_node_id":355,"url_alias":"Products\/blablabla\/blablabla\/139930-blablabla","depth":6,"path":false,"children_count":false,"image_attributes":["main_image","listing_thumbnail","promo_badge"],"data_map":{"title":{"id":"6488","type":"ezstring","identifier":"title","content":"blablabla"},"short_title":{"id":"6489","type":"ezstring","identifier":"short_title","content":"139930 blablabla"},"subtitle":{"id":"6490","type":"ezstring","identifier":"subtitle","content":""},"authors":{"id":"6491","type":"ezauthor","identifier":"authors","content":"blablabla blablabla | [email protected] blablabla .com|0"},"keywords":{"id":"6492","type":"ezkeyword","identifier":"keywords","content":"blablabla"},"item_id":{"id":"6493","type":"ezstring","identifier":"item_id","content":"139930"},"price":{"id":"6494","type":"ezprice","identifier":"price","content":"0|1|1"},"is_shoppable":{"id":"6495","type":"ezboolean","identifier":"is_shoppable","content":"0"},"main_image":{"id":"6496","type":"ezimage","identifier":"main_image","content":{"reference":false,"small":{"name":"small","width":"100","height":"33","mime_type":"image\/jpeg","filename":"139930-blablabla_small.jpg","suffix":"jpg","dirpath":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/lawn-blablabla\/blablabla\/139930-blablabla\/6496-25-eng-EU","alias_key":"2343348577","timestamp":"1286700665","is_valid":"1","url":"var\/blablabla\/storage\/images\/frontpage\/products\/blablabla-care\/blablabla\/139930-blablabla/6496-25-eng-EU\/139930-blablabla-blablablar_small.jpg","basename":"139930-blablabla-blablablar","alternative_text":"","text":"","original_filename":"139930_2.jpg","full_path":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/blab-bla\/blaaders\/139930-blablabla-blablablar\/6496-25-eng-EU\/139930-blablabla-blablablar_small.jpg","is_new":false,"info":{"Height":"200","Width":"600","IsColor":"1"}},"tiny":false,"medium":false,"large":false,"rss":false,"width100":false,"width150":false,"width200":false,"width300":false,"width400":false,"product_main":false,"product_main_large":false,"product_listing":false,"product_category_listing":false,"product_media_listing":false,"rc_full":false,"main_banner":false,"main_banner_front":false,"promo_badge":false,"multiuploadthumbnail":false,"original":{"url":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/blab-bla\/blaaders\/139930-blablabla-blablablar\/6496-25-eng-EU\/139930-blablabla-blablablar.jpg|"}}},"listing_thumbnail":{"id":"6497","type":"ezimage","identifier":"listing_thumbnail","content":{"reference":false,"small":null,"tiny":false,"medium":false,"large":false,"rss":false,"width100":false,"width150":false,"width200":false,"width300":false,"width400":false,"product_main":false,"product_main_large":false,"product_listing":false,"product_category_listing":false,"product_media_listing":false,"rc_full":false,"main_banner":false,"main_banner_front":false,"promo_badge":false,"multiuploadthumbnail":false,"original":{"url":"var\/blablabal_blablabal\/storage\/images\/frontpage\/products\/blab-bla\/blaaders\/139930-blablabla-blablablar\/6497-25-eng-EU\/139930-blablabla-blablablar.jpg|"}}},"related_images":{"id":"6498","type":"ezobjectrelationbrowse","identifier":"related_images","content":"605"},"related_media":{"id":"6499","type":"ezobjectrelationbrowse","identifier":"related_media","content":""},"related_products":{"id":"6500","type":"ezobjectrelationbrowse","identifier":"related_products","content":""},"related_faq_items":{"id":"6501","type":"ezobjectrelationbrowse","identifier":"related_faq_items","content":""},"awards":{"id":"6502","type":"ezxmltext","identifier":"awards","content":"\n 
     \n"},"country_awards":{"id":"601924","type":"ezxmltext","identifier":"country_awards","content":"\n 


    \n"},"description":{"id":"6503","type":"ezxmltext","identifier":"description","content":"\n 
     blablabla<\/line><\/paragraph><\/section>\n"},"features":{"id":"6504","type":"ezxmltext","identifier":"features","content":"\n 
     • blablabla <\/paragraph><\/li> 
     • blablabla <\/paragraph><\/li> 
     • blablabla <\/paragraph><\/li> 
     • blablabla <\/paragraph><\/li> 
     • C blablabla <\/paragraph><\/li><\/ul><\/paragraph><\/section>\n"},"freeform_1_title":{"id":"6505","type":"ezstring","identifier":"freeform_1_title","content":""},"freeform_1_content":{"id":"6506","type":"ezxmltext","identifier":"freeform_1_content","content":"\n\n"},"freeform_2_title":{"id":"6507","type":"ezstring","identifier":"freeform_2_title","content":""},"freeform_2_content":{"id":"6508","type":"ezxmltext","identifier":"freeform_2_content","content":"\n\n"},"freeform_3_title":{"id":"6509","type":"ezstring","identifier":"freeform_3_title","content":""},"freeform_3_content":{"id":"6510","type":"ezxmltext","identifier":"freeform_3_content","content":"\n\n"},"promo_badge":{"id":"277833","type":"ezimage","identifier":"promo_badge","content":{"reference":false,"small":null,"tiny":false,"medium":false,"large":false,"rss":false,"width100":false,"width150":false,"width200":false,"width300":false,"width400":false,"product_main":false,"product_main_large":false,"product_listing":false,"product_category_listing":false,"product_media_listing":false,"rc_full":false,"main_banner":false,"main_banner_front":false,"promo_badge":false,"multiuploadthumbnail":false,"original":{"url":"|"}}},"weight":{"id":"433850","type":"ezstring","identifier":"weight","content":"1052"},"length":{"id":"433851","type":"ezstring","identifier":"length","content":"970"},"product_attributes":{"id":"691877","type":"blamatrix","identifier":"product_attributes","content":{"HTTPValue":null,"Content":null,"DisplayInfo":null,"IsValid":null,"ContentClassAttributeID":"891","ValidationError":null,"ValidationLog":null,"ContentClassAttributeIdentifier":"product_attributes","ContentClassAttributeCanTranslate":null,"ContentClassAttributeName":null,"ContentClassAttributeIsInformationCollector":null,"ContentClassAttributeIsRequired":null,"PersistentDataDirty":false,"InputParameters":false,"HasValidationError":false,"DataTypeCustom":null,"ID":"691877","ContentObjectID":"599","Version":"26","LanguageCode":"eng-EU","LanguageID":"8","AttributeOriginalID":"0","SortKeyInt":"0","SortKeyString":"","DataTypeString":"blamatrix","DataText":"\n<\/name>Title<\/column>Content<\/column><\/columns>Description<\/b><ul><li>I NEED THIS DESC TEXT<\/li><\/ul><\/b>SOME TITLE<\/b><ul><li>THIS TEXT<\/li><\/ul><\/b>THIS TITLE<\/b>THIS TEXT<\/b>THIS TITLE<\/b>AGAIN THIS TEXT<\/b>THIS TITLE<\/b><ul><li>THIS TEXAT<\/li><\/ul><\/b>THIS TITLE<\/b><ul><li>THIS TEXT<\/li><\/ul><\/b>YEP THIS TITLE<\/b>THIS<\/b><\/blamatrix>\n","DataInt":null,"DataFloat":"0"}}}}] 
+1

這應該可能是對原始問題的編輯,不會作爲答案發布。我自己做編輯,但沒有必要的代表。 – 2010-10-20 14:45:50

+0

沒有人不能提供任何幫助? :( – peter 2010-10-20 19:47:17