在JS中提取困难文件时,我需要一些帮助 .
我想从文件中提取一类actor . 该文件的原始格式是XML,但是,稍后在文件中,所有信息都保存在"text"属性下,这使得难以获得特定的信息和平,即出生日期等 . 我可以访问 Headers ,信息存储在属性中(我也可以访问)但是从那里我很困惑如何访问信息的剩余部分,因为它没有提供2个不同的属性示例:

例1: -

<page>
    <title>Ahn Bo-hyun</title>
    <ns>0</ns>
    <id>49961849</id>
    <revision>
      <id>871351259</id>
      <parentid>860534373</parentid>
      <timestamp>2018-11-30T13:48:26Z</timestamp>
      <contributor>
        <username>Redalert2fan</username>
        <id>17311078</id>
      </contributor>
      <comment>Importing Wikidata [[Wikipedia:Short description|short description]]: "South Korean actor" ([[User:Galobtter/Shortdesc helper|Shortdesc helper]])</comment>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text xml:space="preserve" bytes="3230">{{short description|South Korean actor}}
{{Korean name|Ahn}}
{{Infobox person
| name            = Ahn Bo-hyun 
| image           =
| image_size      = 
| birth_date      = {{birth date and age|1988|5|16}}
| birth_place     = [[Busan]], [[South Korea]]
| occupation      = [[Actor]] &amp; [[Model (person)|Model]]
| years_active    = 
| education       = [[Daekyeung University]] – Department of Modeling 
| agent           = FN Entertainment 
| module          = {{Infobox Korean name|child=yes|color=transparent|
| hangul          = 안보현
| hanja           = 
| rr              = An Bo-hyeon
| mr              = An Po-hyŏn
}}}}

'''Ahn Bo-hyun''' (born May 16, 1988) is a [[South Korea]]n actor. He debuted as a model.&lt;ref&gt;{{cite web|first1=Ara|last1=Oh|title=[bnt pictorial] Actor Ahn Bo-Hyun, 'As One Says'|url=http://www.bntnews.co.uk/app/news.php?nid=29543|website=BNTNews|accessdate=2016-03-27|date=22 March 2016}}&lt;/ref&gt;&lt;ref&gt;{{cite web|first1=Nawael|last1=Khelil|title=Model Ahn Bo-Hyun Will Protect ''The Secret Hotel''|url=http://bntnews.co.uk/app/news.php?nid=12650|website=BNTNews|accessdate=2016-03-27|date=14 August 2014}}&lt;/ref&gt;

== Filmography ==

===Film===
{| class="wikitable"
|-
! Year
! Title
! Role
|-
| 2016
| [[Hiya (film)|''Hiya'']]&lt;ref&gt;{{cite web|title=INFINITE's Hoya and Ahn Bo-Hyun Discuss How Similar They Are to Their Characters in ''Hiya''|url=http://www.soompi.com/2016/02/29/infinites-hoya-and-ahn-bo-hyun-discuss-how-similar-they-are-to-their-characters-in-heeya/|website=[[Soompi]]|accessdate=2016-03-27|date=29 February 2016}}&lt;/ref&gt; 
|  Lee Jin-sang
|-
|2018
|''Dokgo Rewind''
|Pyo Taejin
|-
|}

===Television series===
{| class="wikitable"
|-
! Year
! Title
! Role
! Network
|-
| rowspan="3"| 2014
| [[Golden Cross (TV series)|''Golden Cross'']]
| 
| rowspan=2|[[KBS2]]
|-
| [[Two Mothers (TV series)|''Two Mothers'']]
| 
|-
| ''[[My Secret Hotel]]''
| Sang-hoon 
| [[TVN (South Korea)|tvN]]
|-
| 2015
| ''The Dearest Lady''
| Lee Bong-gil 
| [[Munhwa Broadcasting Corporation|MBC]]
|-
| rowspan="3"| 2016
| [[Descendants of the Sun]]
| Im Kwang-nam 
| KBS2
|-
| ''After the Show Ends ''
| Cha Kang-woo
|tvN
|-
| ''My Runway ''
| Wang Rin
| [[MBC Plus Media|MBC Dramanet]]
|-
| rowspan="2"| 2017
| ''[[Wednesday 3:30 PM]]''
| Baek Seung-kyu
| [[SBS Plus]]
|-
| ''[[My Only Love Song]]''
| Moo-myung
| [[Netflix]]
|-
| 2018
| ''[[Hide and Seek (TV series)|Hide and Seek]]''&lt;ref&gt;{{cite web|url=https://entertain.naver.com/read?oid=213&amp;aid=0001045634|title=안보현, MBC 새 주말극 ‘숨바꼭질’ 합류…"대선배들과 연기, 영광"|date=July 3, 2018|website=TV Report|language=ko}}&lt;/ref&gt;
| Baek Do-hoon
|MBC 
|}

== References ==
{{reflist|30em}}

== External links ==
&lt;!-- Per [[WP:ELMINOFFICIAL]], choose one official website only --&gt;
* [http://www.fnent.co.kr/portfolio-item/ahn-bo-hyun/ Ahn Bo-hyun] at FN Entertainment
* {{HanCinema person}}
* {{IMDb name|8003645|Ahn Bo-hyun}}
* {{KMDb person|00195445|Ahn Bo-hyun}}


{{authority control}}

{{DEFAULTSORT:Ahn, Bo-hyun}}
[[Category:1988 births]]
[[Category:Living people]]
[[Category:South Korean male actors]]
[[Category:South Korean male television actors]]
[[Category:South Korean male film actors]]


{{Korea-actor-stub}}</text>
      <sha1>23w7g1jsavave03edcycmscv8m4vd43</sha1>
    </revision>
  </page>

例2: -

<page>
    <title>Kim Sung-soo (actor)</title>
    <ns>0</ns>
    <id>4462733</id>
    <revision>
      <id>840611520</id>
      <parentid>839930891</parentid>
      <timestamp>2018-05-10T23:56:31Z</timestamp>
      <contributor>
        <username>Cydebot</username>
        <id>1215485</id>
      </contributor>
      <minor/>
      <comment>Robot - Removing category Law of the Jungle cast members per [[WP:CFD|CFD]] at [[Wikipedia:Categories for discussion/Log/2017 June 30]].</comment>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text xml:space="preserve" bytes="7584">{{Not to be confused|Kim Seung-soo}}
{{Korean name|Kim}}
{{Infobox person
| name        = Kim Sung-soo
| image       = Kim Sung-soo (South Korean actor) from acrofan.jpg
| alt         = 
| caption     = 
| birth_date  = {{Birth date and age|1973|5|23}}
| birth_place = [[South Korea]]
| nationality = [[South Korea]]n
| occupation  = [[Actor]], [[television host]]
| years_active= 1997–present
| religion    =
| agent       = [[Fantagio]]
| module      = {{Infobox Korean name|child=yes
| hangul      = 김성수
| hanja       = {{linktext|金|聖|洙}}
| rr          = Gim Seong-su
| mr          = Kim Sŏng-su
}}}}
'''Kim Sung-soo''' (born May 23, 1973) is a South Korean actor and television host. After beginning his career as a fashion model, Kim made his acting debut in the [[tokusatsu]] series ''Vectorman'' and the erotic film ''[[The Sweet Sex and Love]]''. He has since appeared in the movies ''[[The Red Shoes (2005 film)|The Red Shoes]]''&lt;ref&gt;{{cite web|title=K-FILM REVIEWS: 분홍신 (The Red Shoes)|url=http://twitchfilm.com/2005/11/the-red-shoes-dvd-review.html|work=[[Twitch Film]]|accessdate=2012-12-17|date=10 November 2005|deadurl=yes|archiveurl=https://web.archive.org/web/20121221091623/http://twitchfilm.com/2005/11/the-red-shoes-dvd-review.html|archivedate=21 December 2012|df=}}&lt;/ref&gt; and ''[[R2B: Return to Base]]'',&lt;ref&gt;{{cite web|last=Lee|first=Jin-ho|title=''R2B''s Kim Sung Soo – "Rain Doesn’t Seem to be Adjusting to Military Life Well"|url=http://enewsworld.mnet.com/enews/contents.asp?idx=9822|accessdate=2012-11-18|work=enewsWorld|date=14 July 2012}}&lt;/ref&gt; and several television series, including ''[[Full House (2004 TV series)|Full House]]'', ''[[My Precious You]]'',&lt;ref&gt;{{cite web|last=Oh|first=Jean|title=Youthful drama targets weekend audience|url=http://www.hancinema.net/youthful-drama-targets-weekend-audience-16044.html|work=[[The Korea Herald]] via [[Hancinema]]|accessdate=2013-04-20|date=2 October 2008}}&lt;/ref&gt;&lt;ref&gt;{{cite web|title=Actor Kim Sung-su Vows to Give All to Acting|url=http://english.kbs.co.kr/news/entertainment_news_view.html?No=3|work=KBS Global|accessdate=2013-07-02|date=1 April 2009}}&lt;/ref&gt; ''More Charming by the Day'' and ''[[My Lover, Madame Butterfly]]''.&lt;ref&gt;{{cite web|last=Jeon|first=Su-mi|title=Kim Sung Soo to Return to Television with ''My Love, Madame Butterfly''|url=http://enewsworld.mnet.com/enews/contents.asp?idx=16076|work=enewsWorld|accessdate=2012-12-17|date=26 September 2012}}&lt;/ref&gt; In 2009 he made his stage debut in the play ''Mom, Do You Want to Go on a Trip?''&lt;ref&gt;{{cite web|title=Two heart-warming plays with brilliant casting (가을소나타 &amp; 엄마, 여행갈래요?)|url=http://www.newsculture.tv/sub_read.html?uid=14459|work=News Culture|accessdate=2012-12-17}}&lt;/ref&gt;&lt;ref&gt;{{cite web|last=Kim|first=Lynn|title=Kim Sung-su wraps up Japan fan meeting in success|url=http://www.asiae.co.kr/news/view.htm?idxno=2009113011160886479|work=10Asia|accessdate=2012-12-17|date=30 November 2009}}&lt;/ref&gt;

More recently, Kim has expanded his career to variety shows. He was a regular on the popular reality show ''[[Invincible Baseball Team]]'', and was the host of talk show ''Win Win'' in 2010. He also hosted several programs on [[Cable television|cable]], including fashion program ''Homme'', bowling show ''Lucky Strike 300'' and food show ''Noodle Myeongga''.&lt;ref&gt;{{cite web|title=KIM Sung-su|url=http://www.koreanfilm.or.kr/jsp/films/index/peopleView.jsp?peopleCd=10004594|work=Korean Film Council|accessdate=2012-12-17}}&lt;/ref&gt;

== Filmography ==
=== Film ===
* ''Hero Vectorman: Counterattack of the Evil Empire'' (1999)
* ''[[The Sweet Sex and Love]]'' (2003)
* ''[[The Red Shoes (2005 film)|The Red Shoes]]'' (2005)
* ''Monopoly'' (2006)
* ''[[Hellcats (film)|Hellcats]]'' (2008)
* ''California High Noon'' ([[short film]], 2010)
* ''[[R2B: Return to Base]]'' (2012)
* ''[[Fasten Your Seatbelt (film)|Fasten Your Seatbelt]]'' (2013) - [[cameo appearance|cameo]]
* ''The Black Hand'' (2015)

=== Television series ===
* ''[[:ko:지구용사 벡터맨|Vectorman: Warriors of the Earth 2]]'' ([[KBS2]], 1999)
* ''Say You Love Me'' ([[Munhwa Broadcasting Corporation|MBC]], 2004)
* ''[[Full House (2004 TV series)|Full House]]'' ([[KBS2]], 2004)
* ''[[Stained Glass (TV series)|Stained Glass]]'' ([[Seoul Broadcasting System|SBS]], 2004)
* ''[[Lawyers (TV series)|Lawyers]]'' ([[Munhwa Broadcasting Corporation|MBC]], 2005)
* ''[[My Beloved Sister]]'' ([[Munhwa Broadcasting Corporation|MBC]], 2006)
* ''[[Cruel Love]]'' ([[KBS2]], 2007)
* ''[[My Precious You]]'' ([[KBS2]], 2008)
* ''More Charming by the Day'' ([[Munhwa Broadcasting Corporation|MBC]], 2010)
* ''[[The Slave Hunters]]'' ([[KBS2]], 2010) - cameo
* ''Suspicious Family'' ([[Maeil Broadcasting Network|MBN]], 2012)
* ''[[My Lover, Madame Butterfly]]'' ([[Seoul Broadcasting System|SBS]], 2012)
* ''After School: Lucky or Not'' ([[Nate (web portal)|Nate]]/[[HanaTV|BTV]]/T-store/Hoppin, 2013) - cameo (ep 3)
* ''[[Can We Fall in Love, Again?]]'' ([[jTBC]], 2014)
* ''[[Should We Kiss First]]'' (SBS, 2018)

=== Variety show ===
*''Star N the City: Kim Sung-soo in [[London]]'' ([[XTM (TV channel)|XTM]], 2009)
*''[[Saturday Freedom|Invincible Saturday]]: [[Invincible Baseball Team]]'' ([[KBS2]], 2009)
*''Homme 1.0'' ([[XTM (TV channel)|XTM]], 2009) - MC
*''Win Win'' ([[KBS2]], 2010) - MC
*''Homme 2.0'' ([[XTM (TV channel)|XTM]], 2010) - MC
*''Lucky Strike 300'' ([[XTM (TV channel)|XTM]], 2010) - MC
*''[[Saturday Night Live Korea]]'' ([[TVN (South Korea)|tvN]], 2012-01-14) - Host, episode 7&lt;ref&gt;{{cite web|title=김성수 "내 생애 마지막 '벡터맨' 되겠다" 파격변신 예고|url=http://osen.mt.co.kr/article/G1109340149|trans-title=Kim Sung-soo hosts SNL Korea|work=Osen|accessdate=2012-12-17|date=10 January 2010}}&lt;/ref&gt;
*''Noodle Myeongga'' ([[O'live|Olive TV]], 2012) - MC
*''[[MasterChef Korea Celebrity]]'' ([[O'live|Olive TV]], 2013)
*''[[Law of the Jungle (TV series)#Caribbean &amp; Maya Jungle|Law of the Jungle in Caribbean/Maya Jungle]]'' ([[Seoul Broadcasting System|SBS]], 2013)
*''Law of the City in New York'' ([[Seoul Broadcasting System|SBS]], 2014)

=== Music video ===
*"Never Ending Story" ([[Boohwal]], 2002)
*"추억은 시간이 지운다" ([[:ko:유미|Youme]], 2005)

== Theater ==
*''Mom, Do You Want to Go on a Trip?'' (2009)

== Discography ==
*''As Time Goes By'' ([[single (music)|single]], 2011)&lt;ref&gt;{{cite web|last=Choi|first=Min-ji|title=Kim Sung Soo Makes Singing Debut|url=http://enewsworld.mnet.com/enews/contents.asp?idx=394|work=enewsWorld|accessdate=2012-12-17|date=15 September 2011}}&lt;/ref&gt;

== Awards ==
*2004 [[SBS Drama Awards]]: New Star Award (''[[Stained Glass (TV series)|Stained Glass]]'')
*2007 Korean Model Awards: Model Star Award, Fashion model category
*2008 Jewelry Awards: Ruby Award
*2009 [[Style Icon Awards]]: Male [[Cyon]] New Chocolate Fashionista
*2010 [[MBC Entertainment Awards]]: Top Excellence Award, Actor in a Sitcom/Comedy (''More Charming by the Day'')
*2013 [[SBS Entertainment Awards]]: Popularity Award (''[[Law of the Jungle (TV series)#Caribbean &amp; Maya Jungle|Law of the Jungle in Caribbean/Maya Jungle]]'')

== References ==
{{reflist|2}}

== External links ==
* {{Facebook|ft.kimsungsu|Kim Sung-su}}
* {{KMDb person|00003901|Kim Sung-su}}
* {{IMDb name|1372796|Kim Seong-su}}
* {{HanCinema person}}

{{Authority control}}
{{DEFAULTSORT:Kim, Sung-soo}}
[[Category:South Korean male television actors]]
[[Category:South Korean male film actors]]
[[Category:South Korean male models]]
[[Category:1973 births]]
[[Category:Living people]]</text>
      <sha1>rkvtf4qcpstn72mt6y5iwtbt1kz2gm4</sha1>
    </revision>
  </page>

我想要在我的变量中提取的信息包括姓名,birth_date,birth_place,国籍,职业,years_active,hangul,电影(电影名称和年份),电视连续剧(姓名和年份) .
请注意,我是JavaScript的新手,所以我现在还在学习 . 到目前为止,我已尝试过以下方法: -

var fs = require('fs'),
    xml2js = require('xml2js');

var parser = new xml2js.Parser();

fs.readFile('./xml/koreanActorDetails.xml', (err, data) => {
    parser.parseString(data, (err, result) => {
        for(i = 0; i < result.mediawiki.page.length; i++){
            if(err)return console.log(err);
            var title = result.mediawiki.page[i].title[0];
            var text = result.mediawiki.page[i].revision[0].text[0]._;
            var infoPerson = text.split('{{Infobox person').pop().split('}}}}')[0];
            var birthDate = infoPerson.split('| birth_date      = {{birth date and age|').pop().split('}}')[0];
            //example output - "1988|5|16"
            var birthPlace = infoPerson.split('| birth_place     = ').pop().split('| occupation      = ')[0];
            //example output - "[[Busan]], [[South Korea]]"


            console.log('Title: ' + title + "\n" +
                        'Text: ' + infoPerson);
        }
    });
});

任何指导都受到广泛赞赏,请为代码提供一些解释,因为我还在学习JS . 到目前为止,我一直在使用YouTube来学习这个提取过程并浏览SO;但是,我想询问它们是否是一种合适的方式,即使用不同的库或更改格式(只是猜测) .

如果任何人都可以粗略地了解它是如何实现的,或者通过解释帮助我提取信息,那么我应该能够将其与其他属性相适应 . 欢迎任何进一步的问题 .