Go에서 XML 배열 역마샬링: 모든 요소 캡처
제공된 코드에서 여러 인스턴스가 포함된 XML 문자열을 역마샬링할 때 문제가 발생합니다. 특정 구조체 유형. 현재 구현에서는 배열의 첫 번째 요소만 검색합니다.
이 제한을 극복하려면 다음 접근 방식을 고려하세요.
XML 디코더 사용
xml.Decoder를 활용하면 XML 데이터를 반복하고 구조체의 모든 인스턴스를 검색할 수 있습니다. 업데이트된 코드는 다음과 같습니다.
<code class="go">package main import ( "bytes" "encoding/xml" "fmt" "io" "log" ) type HostSystemIdentificationInfo struct { IdentiferValue string `xml:"identifierValue"` IdentiferType struct { Label string `xml:"label"` Summary string `xml:"summary"` Key string `xml:"key"` } `xml:"identifierType"` } func main() { d := xml.NewDecoder(bytes.NewBufferString(VV)) for { var t HostSystemIdentificationInfo err := d.Decode(&t) if err == io.EOF { break } if err != nil { log.Fatal(err) } fmt.Println(t) } } const VV = `<hostsystemidentificationinfo xsi:type="HostSystemIdentificationInfo"> <identifiervalue> unknown</identifiervalue> <identifiertype> <label>Asset Tag</label> <summary>Asset tag of the system</summary> <key>AssetTag</key> </identifiertype> </hostsystemidentificationinfo> <hostsystemidentificationinfo xsi:type="HostSystemIdentificationInfo"> <identifiervalue>Dell System</identifiervalue> <identifiertype> <label>OEM specific string</label> <summary>OEM specific string</summary> <key>OemSpecificString</key> </identifiertype> </hostsystemidentificationinfo> <hostsystemidentificationinfo xsi:type="HostSystemIdentificationInfo"> <identifiervalue>5[0000]</identifiervalue> <identifiertype> <label>OEM specific string</label> <summary>OEM specific string</summary> <key>OemSpecificString</key> </identifiertype> </hostsystemidentificationinfo> <hostsystemidentificationinfo xsi:type="HostSystemIdentificationInfo"> <identifiervalue>REDACTED</identifiervalue> <identifiertype> <label>Service tag</label> <summary>Service tag of the system</summary> <key>ServiceTag</key> </identifiertype> </hostsystemidentificationinfo>`</code>
Go로 플레이하기:
[Playground Link](http://play.golang.org/p/c7-E_Afe -3)
위 내용은 Go에서 XML 언마샬링 중 모든 배열 요소를 검색하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

go'selectStatementsTreamLinesconcurramprogrammingBymultiplexingOperations.1) ItallowSwaitingOnMultipLechannelOperations, executingThefirStreadYone.2) thedefaultCasePreventsDeadLocksHavingThepRamToproCeedifNooperationSready.3) Itcanusedfored

Contextandwaitgroupsarecrucialingformaninggoroutineeseforoutineeseferfectial

goisbeneficialformicroservicesduetoitssimplicity, 효율성, AndrobustConcurrenCysupport.1) Go'sdesignempasizessimplicityandefficiency, 이상적인 formicroservices.2) itsconcurrencymodelusinggoroutinesandChannelsAnllingoSyhighconcrency.3) FASTCOMPI

golangisidealforbuildingscalablesystemsdueToitsefficiencyandconcurrency

Golang은 동시성에서 C보다 낫고 C는 원시 속도에서 Golang보다 낫습니다. 1) Golang은 Goroutine 및 Channel을 통해 효율적인 동시성을 달성하며, 이는 많은 동시 작업을 처리하는 데 적합합니다. 2) C 컴파일러 최적화 및 표준 라이브러리를 통해 하드웨어에 가까운 고성능을 제공하며 극도의 최적화가 필요한 애플리케이션에 적합합니다.

Golang을 선택하는 이유는 다음과 같습니다. 1) 높은 동시성 성능, 2) 정적 유형 시스템, 3) 쓰레기 수집 메커니즘, 4) 풍부한 표준 라이브러리 및 생태계는 효율적이고 신뢰할 수있는 소프트웨어를 개발하기에 이상적인 선택입니다.

Golang은 빠른 개발 및 동시 시나리오에 적합하며 C는 극도의 성능 및 저수준 제어가 필요한 시나리오에 적합합니다. 1) Golang은 쓰레기 수집 및 동시성 메커니즘을 통해 성능을 향상시키고, 고전성 웹 서비스 개발에 적합합니다. 2) C는 수동 메모리 관리 및 컴파일러 최적화를 통해 궁극적 인 성능을 달성하며 임베디드 시스템 개발에 적합합니다.

Golang은 컴파일 시간과 동시 처리에서 더 나은 성능을 발휘하는 반면 C는 달리기 속도 및 메모리 관리에서 더 많은 장점을 가지고 있습니다. 1. 골랑은 빠른 컴파일 속도를 가지고 있으며 빠른 개발에 적합합니다. 2.C는 빠르게 실행되며 성능 크리티컬 애플리케이션에 적합합니다. 3. Golang은 동시 처리에 간단하고 효율적이며 동시 프로그래밍에 적합합니다. 4.C 수동 메모리 관리는 더 높은 성능을 제공하지만 개발 복잡성을 증가시킵니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)
