主頁 > 移動端開發 > 快速決議xml檔案

快速決議xml檔案

2022-10-10 10:40:08 移動端開發

我正在嘗試使用 Swift 決議 xml 檔案并將其存盤為以后可以輕松訪問資料的方式。我特別想提取名字和姓氏、cid nimber 和電話號碼。我對如何做到這一點感到困惑,因為我以前從未決議過 xml 檔案。任何幫助,將不勝感激!

我試過的:

    func parseData() {
        let xmlResponseData = Bundle.main.getFileData("data.xml")
        let parser = XMLParser(data: xmlResponseData)
        parser.delegate = self
        parser.parse()
    }

XML 檔案:

    <legislator cid="N00033987" firstlast="Doug LaMalfa" lastname="Lamalfa" party="R" office="CA01" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-3076" fax="530-534-7800" website="http://lamalfa.house.gov" webform="https://lamalfa.house.gov/contact/email-me" congress_office="322 Cannon House Office Building" bioguide_id="L000578" votesmart_id="29713" feccandid="H2CA02142" twitter_id="RepLaMalfa" youtube_url="https://youtube.com/RepLaMalfa" facebook_id="RepLaMalfa" birthdate="1960-07-02" />
    <legislator cid="N00033030" firstlast="Jared Huffman" lastname="Huffman" party="D" office="CA02" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-5161" fax="202-225-5163" website="http://huffman.house.gov" webform="https://huffman.house.gov/contact/email-me" congress_office="1406 Longworth House Office Building" bioguide_id="H001068" votesmart_id="59849" feccandid="H2CA06259" twitter_id="RepHuffman" youtube_url="https://youtube.com/rephuffman" facebook_id="RepHuffman" birthdate="1964-02-18" />
    <legislator cid="N00030856" firstlast="John Garamendi" lastname="Garamendi" party="D" office="CA03" gender="M" first_elected="2009" exit_code="0 " comments="" phone="202-225-1880" fax="202-225-5914" website="http://garamendi.house.gov" webform="https://garamendi.house.gov/contact-me/email-me" congress_office="2438 Rayburn House Office Building" bioguide_id="G000559" votesmart_id="29664" feccandid="H0CA10149" twitter_id="RepGaramendi" youtube_url="https://youtube.com/garamendiCA10" facebook_id="repgaramendi" birthdate="1945-01-24" />
    <legislator cid="N00006863" firstlast="Tom McClintock" lastname="Mcclintock" party="R" office="CA04" gender="M" first_elected="2008" exit_code="0 " comments="" phone="202-225-2511" fax="202-225-5444" website="http://mcclintock.house.gov" webform="https://mcclintockforms.house.gov/forms/contact-form.shtml" congress_office="2312 Rayburn House Office Building" bioguide_id="M001177" votesmart_id="9715" feccandid="H8CA04152" twitter_id="RepMcClintock" youtube_url="https://youtube.com/McClintockCA04" facebook_id="Congressman-Tom-McClintock-81125319109" birthdate="1956-07-10" />
    <legislator cid="N00007419" firstlast="Mike Thompson" lastname="Thompson" party="D" office="CA05" gender="M" first_elected="1998" exit_code="0 " comments="" phone="202-225-3311" fax="202-225-4335" website="http://mikethompson.house.gov" webform="https://mikethompson.house.gov/contact/email-me" congress_office="231 Cannon House Office Building" bioguide_id="T000460" votesmart_id="3564" feccandid="H8CA01109" twitter_id="RepThompson" youtube_url="https://youtube.com/CongressmanMThompson" facebook_id="RepMikeThompson" birthdate="1951-01-24" />
    <legislator cid="N00027459" firstlast="Doris Matsui" lastname="Matsui" party="D" office="CA06" gender="F" first_elected="2005" exit_code="0 " comments="" phone="202-225-7163" fax="202-225-0566" website="https://matsui.house.gov" webform="https://matsui.house.gov/email-representative-matsui" congress_office="2311 Rayburn House Office Building" bioguide_id="M001163" votesmart_id="28593" feccandid="H6CA05195" twitter_id="DorisMatsui" youtube_url="https://youtube.com/RepDorisMatsui" facebook_id="doris.matsui" birthdate="1944-09-25" />
    <legislator cid="N00030717" firstlast="Ami Bera" lastname="Bera" party="D" office="CA07" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-5716" fax="202-226-1298" website="http://bera.house.gov" webform="https://beraforms.house.gov/forms/writeyourrep/" congress_office="1431 Longworth House Office Building" bioguide_id="B001287" votesmart_id="120030" feccandid="H0CA03078" twitter_id="RepBera" youtube_url="https://youtube.com/repamibera" facebook_id="RepAmiBera" birthdate="1965-03-02" />
    <legislator cid="N00045377" firstlast="Jay Obernolte" lastname="Obernolte" party="R" office="CA08" gender="M" first_elected="2020" exit_code="0 " comments="" phone="202-225-5861" fax="" website="https://obernolte.house.gov/" webform="" congress_office="1029 Longworth House Office Building, Washington, DC 20515" bioguide_id="O000019" votesmart_id="" feccandid="" twitter_id="@JayObernolte" youtube_url="" facebook_id="" birthdate="08/18/70" />
    <legislator cid="N00026926" firstlast="Jerry McNerney" lastname="Mcnerny" party="D" office="CA09" gender="M" first_elected="2006" exit_code="4 " comments="Retiring at end of 117th Congress" phone="202-225-1947" fax="202-225-4060" website="http://mcnerney.house.gov" webform="https://mcnerney.house.gov/contact/email-me" congress_office="2265 Rayburn House Office Building" bioguide_id="M001166" votesmart_id="29474" feccandid="H4CA11081" twitter_id="RepMcNerney" youtube_url="https://youtube.com/RepJerryMcNerney" facebook_id="jerrymcnerney" birthdate="1951-06-18" />
    <legislator cid="N00040853" firstlast="Josh Harder" lastname="Harder" party="D" office="CA10" gender="M" first_elected="2018" exit_code="0 " comments="" phone="202-225-4540" fax="" website="https://harder.house.gov/" webform="" congress_office="131 Cannon House Office Building" bioguide_id="H001090" votesmart_id="" feccandid="" twitter_id="RepJoshHarder" youtube_url="" facebook_id="" birthdate="1986-08-01" />
    <legislator cid="N00030709" firstlast="Mark Desaulnier" lastname="Desaulnier" party="D" office="CA11" gender="M" first_elected="2014" exit_code="0 " comments="" phone="202-225-2095" fax="202-225-5609" website="https://desaulnier.house.gov" webform="" congress_office="115 Cannon House Office Building" bioguide_id="D000623" votesmart_id="" feccandid="H0CA10073" twitter_id="RepDeSaulnier" youtube_url="" facebook_id="RepMarkDeSaulnier" birthdate="1952-03-31" />
    <legislator cid="N00007360" firstlast="Nancy Pelosi" lastname="Pelosi" party="D" office="CA12" gender="F" first_elected="1987" exit_code="0 " comments="" phone="202-225-4965" fax="202-225-8259" website="http://pelosi.house.gov" webform="http://pelosi.house.gov/contact-me/email-me" congress_office="233 Cannon House Office Building" bioguide_id="P000197" votesmart_id="26732" feccandid="H8CA05035" twitter_id="NancyPelosi" youtube_url="https://youtube.com/nancypelosi" facebook_id="NancyPelosi" birthdate="1940-03-26" />
    <legislator cid="N00008046" firstlast="Barbara Lee" lastname="Lee" party="D" office="CA13" gender="F" first_elected="1998" exit_code="0 " comments="" phone="202-225-2661" fax="202-225-9817" website="https://lee.house.gov" webform="http://lee.house.gov/contact-the-office/email-me" congress_office="2267 Rayburn House Office Building" bioguide_id="L000551" votesmart_id="8315" feccandid="H8CA09060" twitter_id="RepBarbaraLee" youtube_url="https://youtube.com/RepLee" facebook_id="RepBarbaraLee" birthdate="1946-07-16" />
    <legislator cid="N00029649" firstlast="Jackie Speier" lastname="Speier" party="D" office="CA14" gender="F" first_elected="2008" exit_code="4 " comments="Retiring at end of 117th Congress" phone="202-225-3531" fax="202-347-0956" website="https://speier.house.gov" webform="https://forms.house.gov/speier/webforms/email_jackie.shtml" congress_office="2465 Rayburn House Office Building" bioguide_id="S001175" votesmart_id="8425" feccandid="H8CA12171" twitter_id="RepSpeier" youtube_url="https://youtube.com/jackiespeierca12" facebook_id="JackieSpeier" birthdate="1950-05-14" />
    <legislator cid="N00033508" firstlast="Eric Swalwell" lastname="Swalwell" party="D" office="CA15" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-5065" fax="" website="https://swalwell.house.gov" webform="http://swalwell.house.gov/contact-me/email-eric/" congress_office="129 Cannon House Office Building" bioguide_id="S001193" votesmart_id="129529" feccandid="H2CA15094" twitter_id="RepSwalwell" youtube_url="https://youtube.com/ericswalwell" facebook_id="CongressmanEricSwalwell" birthdate="1980-11-16" />
    <legislator cid="N00026341" firstlast="Jim Costa" lastname="Costa" party="D" office="CA16" gender="M" first_elected="2004" exit_code="0 " comments="" phone="202-225-3341" fax="202-225-9308" website="https://costa.house.gov" webform="http://www.house.gov/formcosta/issue.htm" congress_office="2081 Rayburn House Office Building" bioguide_id="C001059" votesmart_id="3577" feccandid="H4CA20082" twitter_id="RepJimCosta" youtube_url="https://youtube.com/RepJimCostaCA20" facebook_id="RepJimCosta" birthdate="1952-04-13" />
    <legislator cid="N00026427" firstlast="Ro Khanna" lastname="Khanna" party="D" office="CA17" gender="M" first_elected="2016" exit_code="0 " comments="" phone="202-225-2631" fax="" website="https://khanna.house.gov" webform="" congress_office="513 Cannon House Office Building" bioguide_id="K000389" votesmart_id="" feccandid="" twitter_id="RepRoKhanna" youtube_url="" facebook_id="RepRoKhanna" birthdate="1976-09-13" />
    <legislator cid="N00007335" firstlast="Anna Eshoo" lastname="Eshoo" party="D" office="CA18" gender="F" first_elected="1992" exit_code="0 " comments="" phone="202-225-8104" fax="202-225-8890" website="http://eshoo.house.gov" webform="https://eshoo.house.gov/email-me/" congress_office="241 Cannon House Office Building" bioguide_id="E000215" votesmart_id="26741" feccandid="H8CA12098" twitter_id="RepAnnaEshoo" youtube_url="https://youtube.com/RepAnnaEshoo" facebook_id="RepAnnaEshoo" birthdate="1942-12-13" />
    <legislator cid="N00007479" firstlast="Zoe Lofgren" lastname="Lofgren" party="D" office="CA19" gender="F" first_elected="1994" exit_code="0 " comments="" phone="202-225-3072" fax="202-225-3336" website="https://lofgren.house.gov" webform="http://lofgren.house.gov/contact/" congress_office="1401 Longworth House Office Building" bioguide_id="L000397" votesmart_id="21899" feccandid="H4CA16049" twitter_id="RepZoeLofgren" youtube_url="https://youtube.com/RepZoeLofgren" facebook_id="zoelofgren" birthdate="1947-12-21" />
    <legislator cid="N00038601" firstlast="Jimmy Panetta" lastname="Panetta" party="D" office="CA20" gender="M" first_elected="2016" exit_code="0 " comments="" phone="202-225-2861" fax="" website="https://panetta.house.gov" webform="" congress_office="228 Cannon House Office Building" bioguide_id="P000613" votesmart_id="" feccandid="" twitter_id="RepJimmyPanetta" youtube_url="" facebook_id="RepJimmyPanetta" birthdate="1969-10-01" />
    <legislator cid="N00033367" firstlast="David Valadao" lastname="Valadao" party="R" office="CA21" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-4695" fax="202-226-3196" website="http://valadao.house.gov" webform="http://valadao.house.gov/contact/" congress_office="1728 Longworth House Office Building" bioguide_id="V000129" votesmart_id="120200" feccandid="H2CA20094" twitter_id="RepDavidValadao" youtube_url="https://youtube.com/congressmanvaladao" facebook_id="CongressmanDavidValadao" birthdate="1977-04-14" />
    <legislator cid="N00007248" firstlast="Devin Nunes" lastname="Nunes" party="R" office="CA22" gender="M" first_elected="2002" exit_code="2 " comments="Resigned 1/3/2022" phone="202-225-2523" fax="202-225-3404" website="http://nunes.house.gov" webform="https://nunes.house.gov/contactform/default.aspx" congress_office="1013 Longworth House Office Building" bioguide_id="N000181" votesmart_id="16725" feccandid="H8CA20059" twitter_id="Rep_DevinNunes" youtube_url="https://youtube.com/RepDevinNunes" facebook_id="Congressman-Devin-Nunes-376470350795" birthdate="1973-10-01" />
    <legislator cid="N00028152" firstlast="Kevin McCarthy" lastname="Mccarthy" party="R" office="CA23" gender="M" first_elected="2006" exit_code="0 " comments="" phone="202-225-2915" fax="202-225-2908" website="http://kevinmccarthy.house.gov" webform="https://kevinmccarthy.house.gov/contact/email-me" congress_office="2421 Rayburn House Office Building" bioguide_id="M001165" votesmart_id="28918" feccandid="H6CA22125" twitter_id="GOPLeader" youtube_url="https://youtube.com/repkevinmccarthy" facebook_id="CongressmanKevinMcCarthy" birthdate="1965-01-26" />
    <legislator cid="N00037015" firstlast="Salud Carbajal" lastname="Carbajal" party="D" office="CA24" gender="M" first_elected="2016" exit_code="0 " comments="" phone="202-225-3601" fax="" website="https://carbajal.house.gov" webform="" congress_office="212 Cannon House Office Building" bioguide_id="C001112" votesmart_id="" feccandid="" twitter_id="RepCarbajal" youtube_url="" facebook_id="repsaludcarbajal" birthdate="1964-11-18" />
    <legislator cid="N00044298" firstlast="Mike Garcia" lastname="Garcia" party="R" office="CA25" gender="M" first_elected="2020" exit_code="0 " comments="" phone="" fax="" website="" webform="" congress_office="" bioguide_id="" votesmart_id="" feccandid="" twitter_id="" youtube_url="" facebook_id="" birthdate="" />
    <legislator cid="N00034254" firstlast="Julia Brownley" lastname="Brownley" party="D" office="CA26" gender="F" first_elected="2012" exit_code="0 " comments="" phone="202-225-5811" fax="202-225-1100" website="http://juliabrownley.house.gov" webform="https://juliabrownley.house.gov/contact/email-me" congress_office="1019 Longworth House Office Building" bioguide_id="B001285" votesmart_id="59904" feccandid="H2CA00120" twitter_id="JuliaBrownley26" youtube_url="https://youtube.com/RepJuliaBrownley" facebook_id="RepJuliaBrownley" birthdate="1952-08-28" />
    <legislator cid="N00030600" firstlast="Judy Chu" lastname="Chu" party="D" office="CA27" gender="F" first_elected="2009" exit_code="0 " comments="" phone="202-225-5464" fax="202-225-5467" website="https://chu.house.gov" webform="http://chu.house.gov/connect-with-me/email-judy" congress_office="2423 Rayburn House Office Building" bioguide_id="C001080" votesmart_id="16539" feccandid="H0CA32101" twitter_id="RepJudyChu" youtube_url="https://youtube.com/RepJudyChu" facebook_id="RepJudyChu" birthdate="1953-07-07" />
    <legislator cid="N00009585" firstlast="Adam Schiff" lastname="Schiff" party="D" office="CA28" gender="M" first_elected="2000" exit_code="0 " comments="" phone="202-225-4176" fax="202-225-5828" website="http://schiff.house.gov" webform="https://schiff.house.gov/email-congressman-schiff1" congress_office="2372 Rayburn House Office Building" bioguide_id="S001150" votesmart_id="9489" feccandid="H0CA27085" twitter_id="RepAdamSchiff" youtube_url="https://youtube.com/adamschiff" facebook_id="RepAdamSchiff" birthdate="1960-06-22" />
    <legislator cid="N00033373" firstlast="Tony Cardenas" lastname="Cardenas" party="D" office="CA29" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-6131" fax="202-225-0819" website="https://cardenas.house.gov" webform="https://cardenas.house.gov/contact/email-me" congress_office="1510 Longworth House Office Building" bioguide_id="C001097" votesmart_id="9754" feccandid="H2CA28113" twitter_id="RepCardenas" youtube_url="https://youtube.com/repcardenas" facebook_id="repcardenas" birthdate="1963-03-31" />
    <legislator cid="N00006897" firstlast="Brad Sherman" lastname="Sherman" party="D" office="CA30" gender="M" first_elected="1996" exit_code="0 " comments="" phone="202-225-5911" fax="202-225-5879" website="http://sherman.house.gov" webform="http://sherman.house.gov/contact/contact-congressman-sherman-form" congress_office="2181 Rayburn House Office Building" bioguide_id="S000344" votesmart_id="142" feccandid="H6CA24113" twitter_id="BradSherman" youtube_url="https://youtube.com/shermanca27" facebook_id="63158229861" birthdate="1954-10-24" />
    <legislator cid="N00033997" firstlast="Pete Aguilar" lastname="Aguilar" party="D" office="CA31" gender="M" first_elected="2014" exit_code="0 " comments="" phone="202-225-3201" fax="202-226-6962" website="https://aguilar.house.gov" webform="" congress_office="1223 Longworth House Office Building" bioguide_id="A000371" votesmart_id="" feccandid="H2CA31125" twitter_id="reppeteaguilar" youtube_url="" facebook_id="reppeteaguilar" birthdate="1979-06-19" />
    <legislator cid="N00006789" firstlast="Grace Napolitano" lastname="Napolitano" party="D" office="CA32" gender="F" first_elected="1998" exit_code="0 " comments="" phone="202-225-5256" fax="202-225-0027" website="http://napolitano.house.gov" webform="https://napolitano.house.gov/contact-me/email-me" congress_office="1610 Longworth House Office Building" bioguide_id="N000179" votesmart_id="8393" feccandid="H8CA34068" twitter_id="GraceNapolitano" youtube_url="https://youtube.com/RepGraceNapolitano" facebook_id="RepGraceNapolitano" birthdate="1936-12-04" />
    <legislator cid="N00035825" firstlast="Ted Lieu" lastname="Lieu" party="D" office="CA33" gender="M" first_elected="2014" exit_code="0 " comments="" phone="202-225-3976" fax="202-225-4099" website="https://lieu.house.gov" webform="" congress_office="236 Cannon House Office Building" bioguide_id="L000582" votesmart_id="" feccandid="H4CA33119" twitter_id="RepTedLieu" youtube_url="" facebook_id="RepTedLieu" birthdate="1969-03-29" />
    <legislator cid="N00040597" firstlast="Jimmy Gomez" lastname="Gomez" party="D" office="CA34" gender="M" first_elected="2017" exit_code="0 " comments="" phone="202-225-6235" fax="" website="https://gomez.house.gov" webform="" congress_office="1530 Longworth House Office Building" bioguide_id="G000585" votesmart_id="" feccandid="" twitter_id="RepJimmyGomez" youtube_url="" facebook_id="RepJimmyGomez" birthdate="1974-11-25" />
    <legislator cid="N00036107" firstlast="Norma Torres" lastname="Torres" party="D" office="CA35" gender="F" first_elected="2014" exit_code="0 " comments="" phone="202-225-6161" fax="202-225-8671" website="https://torres.house.gov" webform="" congress_office="1713 Longworth House Office Building" bioguide_id="T000474" votesmart_id="" feccandid="H4CA35031" twitter_id="NormaJTorres" youtube_url="" facebook_id="RepNormaTorres" birthdate="1965-04-04" />
    <legislator cid="N00033510" firstlast="Raul Ruiz" lastname="Ruiz" party="D" office="CA36" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-5330" fax="202-225-1238" website="https://ruiz.house.gov" webform="https://ruiz.house.gov/email-me" congress_office="1319 Longworth House Office Building" bioguide_id="R000599" votesmart_id="136407" feccandid="H2CA36439" twitter_id="CongressmanRuiz" youtube_url="https://youtube.com/repraulruiz" facebook_id="CongressmanRaulRuizMD" birthdate="1972-08-25" />
    <legislator cid="N00031877" firstlast="Karen Bass" lastname="Bass" party="D" office="CA37" gender="F" first_elected="2010" exit_code="3 " comments="Running for Mayor of Los Angeles" phone="202-225-7084" fax="202-225-2422" website="https://bass.house.gov" webform="https://bass.house.gov/contact-me/email-me" congress_office="2241 Rayburn House Office Building" bioguide_id="B001270" votesmart_id="28963" feccandid="H0CA33117" twitter_id="RepKarenBass" youtube_url="https://youtube.com/RepKarenBass" facebook_id="RepKarenBass" birthdate="1953-10-03" />
    <legislator cid="N00024870" firstlast="Linda Sanchez" lastname="Sanchez" party="D" office="CA38" gender="F" first_elected="2002" exit_code="0 " comments="" phone="202-225-6676" fax="202-226-1012" website="https://lindasanchez.house.gov" webform="https://forms.house.gov/lindasanchez/webforms/issue_subscribe.htm" congress_office="2329 Rayburn House Office Building" bioguide_id="S001156" votesmart_id="29674" feccandid="H2CA39078" twitter_id="RepLindaSanchez" youtube_url="https://youtube.com/LindaTSanchez" facebook_id="CongresswomanLindaSanchez" birthdate="1969-01-28" />
    <legislator cid="N00042386" firstlast="Young Kim" lastname="Kim" party="R" office="CA39" gender="F" first_elected="2020" exit_code="0 " comments="" phone="202225-4111" fax="" website="https://youngkim.house.gov/" webform="" congress_office="1306 Longworth House Office Building
Washington, DC  20515" bioguide_id="K000397" votesmart_id="151787" feccandid="" twitter_id="@RepYoungKim" youtube_url="" facebook_id="" birthdate="10/18/62" />
    <legislator cid="N00006671" firstlast="Lucille Roybal-Allard" lastname="Roybal-Allard" party="D" office="CA40" gender="F" first_elected="1992" exit_code="4 " comments="Retiring at end of 117th Congress" phone="202-225-1766" fax="202-226-0350" website="http://roybal-allard.house.gov" webform="http://roybal-allard.house.gov/contact/" congress_office="2083 Rayburn House Office Building" bioguide_id="R000486" votesmart_id="26766" feccandid="H2CA33048" twitter_id="RepRoybalAllard" youtube_url="https://youtube.com/RepRoybalAllard" facebook_id="RepRoybalAllard" birthdate="1941-06-12" />
    <legislator cid="N00006701" firstlast="Mark Takano" lastname="Takano" party="D" office="CA41" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-2305" fax="202-225-7018" website="https://takano.house.gov" webform="https://takano.house.gov/contact/email-me" congress_office="1507 Longworth House Office Building" bioguide_id="T000472" votesmart_id="22337" feccandid="H2CA43245" twitter_id="RepMarkTakano" youtube_url="https://youtube.com/RepMarkTakano" facebook_id="RepMarkTakano" birthdate="1960-12-10" />
    <legislator cid="N00007099" firstlast="Ken Calvert" lastname="Calvert" party="R" office="CA42" gender="M" first_elected="1992" exit_code="0 " comments="" phone="202-225-1986" fax="202-225-2004" website="http://calvert.house.gov" webform="https://calvert.house.gov/contactform/" congress_office="2205 Rayburn House Office Building" bioguide_id="C000059" votesmart_id="26777" feccandid="H2CA37023" twitter_id="KenCalvert" youtube_url="https://youtube.com/RepKenCalvert" facebook_id="RepKenCalvert" birthdate="1953-06-08" />
    <legislator cid="N00006690" firstlast="Maxine Waters" lastname="Waters" party="D" office="CA43" gender="F" first_elected="1990" exit_code="0 " comments="" phone="202-225-2201" fax="202-225-7854" website="https://waters.house.gov" webform="https://waters.house.gov/contact/contactform.htm" congress_office="2221 Rayburn House Office Building" bioguide_id="W000187" votesmart_id="26759" feccandid="H4CA23011" twitter_id="MaxineWaters" youtube_url="https://youtube.com/MaxineWaters" facebook_id="MaxineWaters" birthdate="1938-08-15" />
    <legislator cid="N00037019" firstlast="Nanette Barragan" lastname="Barragan" party="D" office="CA44" gender="F" first_elected="2016" exit_code="0 " comments="" phone="202-225-8220" fax="" website="https://barragan.house.gov" webform="" congress_office="1320 Longworth House Office Building" bioguide_id="B001300" votesmart_id="" feccandid="" twitter_id="RepBarragan" youtube_url="" facebook_id="CongresswomanBarragan" birthdate="1976-09-15" />
    <legislator cid="N00040865" firstlast="Katie Porter" lastname="Porter" party="D" office="CA45" gender="F" first_elected="2018" exit_code="0 " comments="" phone="202-225-5611" fax="" website="https://porter.house.gov/" webform="" congress_office="1117 Longworth House Office Building" bioguide_id="P000618" votesmart_id="" feccandid="" twitter_id="" youtube_url="" facebook_id="" birthdate="1974-01-03" />
    <legislator cid="N00037260" firstlast="Lou Correa" lastname="Correa" party="D" office="CA46" gender="M" first_elected="2016" exit_code="0 " comments="" phone="202-225-2965" fax="" website="https://correa.house.gov" webform="" congress_office="1039 Longworth House Office Building" bioguide_id="C001110" votesmart_id="" feccandid="" twitter_id="RepLouCorrea" youtube_url="" facebook_id="RepLouCorrea" birthdate="1958-01-24" />
    <legislator cid="N00033274" firstlast="Alan Lowenthal" lastname="Lowenthal" party="D" office="CA47" gender="M" first_elected="2012" exit_code="4 " comments="Retiring at end of 117th Congress" phone="202-225-7924" fax="202-225-7926" website="http://lowenthal.house.gov" webform="http://lowenthal.house.gov/contact/howtocontactme.htm" congress_office="125 Cannon House Office Building" bioguide_id="L000579" votesmart_id="16469" feccandid="H2CA00104" twitter_id="RepLowenthal" youtube_url="https://youtube.com/RepLowenthal" facebook_id="RepLowenthal" birthdate="1941-03-08" />
    <legislator cid="N00044501" firstlast="Michelle Steel" lastname="Steel" party="R" office="CA48" gender="F" first_elected="2020" exit_code="0 " comments="" phone="202225-2415" fax="" website="https://steel.house.gov/" webform="" congress_office="1113 Longworth House Office Building
Washington, DC  20515" bioguide_id="S001135" votesmart_id="" feccandid="" twitter_id="@RepSteel" youtube_url="" facebook_id="" birthdate="06/21/55" />
    <legislator cid="N00040667" firstlast="Mike Levin" lastname="Levin" party="D" office="CA49" gender="M" first_elected="2018" exit_code="0 " comments="" phone="202-225-3906" fax="" website="https://mikelevin.house.gov/" webform="" congress_office="1626 Longworth House Office Building" bioguide_id="L000593" votesmart_id="" feccandid="" twitter_id="RepMikeLevin" youtube_url="" facebook_id="" birthdate="1978-10-28" />
    <legislator cid="N00007017" firstlast="Darrell Issa" lastname="Issa" party="R" office="CA50" gender="M" first_elected="2000" exit_code="0 " comments="" phone="202-225-3906" fax="202-225-3303" website="https://issa.house.gov" webform="http://issa.house.gov/contact/contact-me" congress_office="2269 Rayburn House Office Building" bioguide_id="I000056" votesmart_id="16553" feccandid="H0CA48024" twitter_id="DarrellIssa" youtube_url="https://youtube.com/repdarrellissa" facebook_id="darrellissa" birthdate="1953-11-01" />
    <legislator cid="N00007021" firstlast="Juan Vargas" lastname="Vargas" party="D" office="CA51" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-8045" fax="202-225-9073" website="http://vargas.house.gov" webform="https://vargas.house.gov/contact" congress_office="1605 Longworth House Office Building" bioguide_id="V000130" votesmart_id="29100" feccandid="H2CA50026" twitter_id="RepJuanVargas" youtube_url="https://youtube.com/RepJuanVargas" facebook_id="RepJuanVargas" birthdate="1961-03-07" />
    <legislator cid="N00033591" firstlast="Scott Peters" lastname="Peters" party="D" office="CA52" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-0508" fax="202-225-2558" website="http://scottpeters.house.gov" webform="https://scottpeters.house.gov/contact/email-me" congress_office="1122 Longworth House Office Building" bioguide_id="P000608" votesmart_id="70351" feccandid="H2CA52089" twitter_id="RepScottPeters" youtube_url="" facebook_id="RepScottPeters" birthdate="1958-06-17" />
    <legislator cid="N00042081" firstlast="Sara Jacobs" lastname="Jacobs" party="D" office="CA53" gender="F" first_elected="2020" exit_code="0 " comments="" phone="202225-2040" fax="202225-2948" website="https://sarajacobs.house.gov/" webform="" congress_office="1232 Longworth HOB
Washington, DC 20515" bioguide_id="J000305" votesmart_id="" feccandid="" twitter_id="@RepSaraJacobs" youtube_url="" facebook_id="" birthdate="02/01/89" />
    <legislator cid="N00047888" firstlast="Alex Padilla" lastname="Padilla" party="D" office="CAS1" gender="M" first_elected="2021" exit_code="0 " comments="Appointed to Senate 1/20/2021" phone="202224- 3553" fax="202224-2200" website="https://www.padilla.senate.gov/" webform="" congress_office="Russell Senate Office Building
Suite B03
Washington, DC 20510" bioguide_id="P000145" votesmart_id="" feccandid="" twitter_id="@SenAlexPadilla" youtube_url="" facebook_id="" birthdate="03/22/73" />
    <legislator cid="N00036915" firstlast="Kamala Harris" lastname="Harris" party="D" office="CAS1" gender="F" first_elected="2016" exit_code="12" comments="Resigned to become Vice-President" phone="202-224-3553" fax="" website="https://www.harris.senate.gov" webform="https://www.harris.senate.gov/content/contact-senator" congress_office="112 Hart Senate Office Building" bioguide_id="H001075" votesmart_id="" feccandid="" twitter_id="SenKamalaHarris" youtube_url="" facebook_id="SenatorKamalaHarris" birthdate="1964-10-20" />
    <legislator cid="N00007364" firstlast="Dianne Feinstein" lastname="Feinstein" party="D" office="CAS2" gender="F" first_elected="1992" exit_code="0 " comments="" phone="202-224-3841" fax="202-228-3954" website="https://www.feinstein.senate.gov" webform="https://www.feinstein.senate.gov/public/index.cfm/e-mail-me" congress_office="331 Hart Senate Office Building" bioguide_id="F000062" votesmart_id="53273" feccandid="S0CA00199" twitter_id="SenFeinstein" youtube_url="https://youtube.com/SenatorFeinstein" facebook_id="senatorfeinstein" birthdate="1933-06-22" />
</response>```

uj5u.com熱心網友回復:

試試這個示例代碼(從我的評論第一個鏈接中回收),對我有用:

import Foundation
import SwiftUI

struct Legislator: Identifiable {
    let id = UUID()
    var cid: String
    var firstlast: String
    var lastname: String
    var party: String
    var office: String
    var gender: String
    var first_elected: String
    var exit_code: String
    var comments: String
    var phone: String
    var fax: String
    var website: String
    var webform: String
    var congress_office: String
    var bioguide_id: String
    var votesmart_id: String
    var feccandid: String
    var twitter_id: String
    var youtube_url: String
    var facebook_id: String
    var birthdate: String
}

struct ContentView: View {
    @State var legislators: [Legislator] = []

    var body: some View {
        VStack {
            List(legislators) { legist in
                HStack {
                    Text(legist.firstlast)
                    Text("phone: "   legist.phone)
                    Text(legist.cid).foregroundColor(.blue)
                }
            }
        }
        .onAppear {
            if let url = Bundle.main.url(forResource: "data", withExtension: "xml") {
                do {
                    let data = try Data(contentsOf: url)
                    let parser = LegislatorParser(data: data)
                    if parser.parse() {
                        legislators = parser.legislators
                    } else {
                        print("---> parser error: \(parser.parserError as Optional)")
                    }
                } catch {
                    print("---> data error: \(error)")
                }
            }
        }
    }
    
}

class LegislatorParser: XMLParser {
    var legislators: [Legislator] = []

    override init(data: Data) {
        super.init(data: data)
        self.delegate = self
    }
}

extension LegislatorParser: XMLParserDelegate {
    
    // Called when opening tag (`<elementName>`) is found
    func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
        
        switch elementName {
        case "legislator":
            let legist = Legislator(
                cid: attributeDict["cid"] ?? "",
                firstlast: attributeDict["firstlast"] ?? "",
                lastname: attributeDict["lastname"] ?? "",
                party: attributeDict["party"] ?? "",
                office: attributeDict["office"] ?? "",
                gender: attributeDict["gender"] ?? "",
                first_elected: attributeDict["first_elected"] ?? "",
                exit_code: attributeDict["exit_code"] ?? "",
                comments: attributeDict["comments"] ?? "",
                phone: attributeDict["phone"] ?? "",
                fax: attributeDict["fax"] ?? "",
                website: attributeDict["website"] ?? "",
                webform: attributeDict["webform"] ?? "",
                congress_office: attributeDict["congress_office"] ?? "",
                bioguide_id: attributeDict["bioguide_id"] ?? "",
                votesmart_id: attributeDict["votesmart_id"] ?? "",
                feccandid: attributeDict["feccandid"] ?? "",
                twitter_id: attributeDict["twitter_id"] ?? "",
                youtube_url: attributeDict["youtube_url"] ?? "",
                facebook_id: attributeDict["facebook_id"] ?? "",
                birthdate: attributeDict["birthdate"] ?? ""
            )
            legislators.append(legist)
            
        default: break
        }
    }
    
    // Called when closing tag (`</elementName>`) is found
    func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
        //...
    }
    
    // Called when a character sequence is found
    func parser(_ parser: XMLParser, foundCharacters string: String) {
        //...
    }
    
    // Called when a CDATA block is found
    func parser(_ parser: XMLParser, foundCDATA CDATABlock: Data) {
        guard String(data: CDATABlock, encoding: .utf8) != nil else {
            print("CDATA contains non-textual data, ignored")
            return
        }
    }
}

data.xml檔案_

<?xml version="1.0" encoding="utf-8"?>
<response>
<legislator cid="N00033987" firstlast="Doug LaMalfa" lastname="Lamalfa" party="R" office="CA01" gender="M" first_elected="2012" exit_code="0 " comments="" phone="202-225-3076" fax="530-534-7800" website="http://lamalfa.house.gov" webform="https://lamalfa.house.gov/contact/email-me" congress_office="322 Cannon House Office Building" bioguide_id="L000578" votesmart_id="29713" feccandid="H2CA02142" twitter_id="RepLaMalfa" youtube_url="https://youtube.com/RepLaMalfa" facebook_id="RepLaMalfa" birthdate="1960-07-02" />
 ....
</response>

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/512186.html

標籤:迅速xmlapi解析xml 解析

上一篇:使用nlohmann的C 庫決議有效JSON資料中的錯誤

下一篇:python中的正則運算式處理多個字串

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more