Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: how to detect two or more roots in xml Date: Thu, 25 Feb 2021 15:29:21 +0100 Organization: A noiseless patient Spider Lines: 80 Message-ID: References: <89601b6a-6ad6-4700-bf59-e9640b3ebafdn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 25 Feb 2021 14:29:28 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="6c915f6f46c2e999efbea8630ef791c6"; logging-data="12577"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dMEUsj4G8IwC4/dbbYRI9" User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cancel-Lock: sha1:Feibm3mGPCiZZcqENw0oCuXuSFk= In-Reply-To: <89601b6a-6ad6-4700-bf59-e9640b3ebafdn@googlegroups.com> X-Antivirus-Status: Clean Content-Language: en-US X-Antivirus: AVG (VPS 210225-0, 02/25/2021), Outbound message Xref: csiph.com comp.lang.java.programmer:39676 On 2021-02-23 18:22, mike wrote: > Hi, > > I will have files like: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I will need to parse to xml: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > However it is not valid xml since it is two roots. How can I detect that I have two roots. Currently I am only seeing this when parse fails ( see below) And message is too general to know there are multiple ( in this case 2) roots. > If I can detect multi roots I can split string and parse each and add them together later ( I think). This looks like a self-inflicted problem. Don't do string manipulations with XML. The first document you posted (starting with a "get" element) is correct. Parse _that_ document. Then extract the children you need -- for instance using XPath. Or build it as a Document and find the children you need. (Apologies, early reply was sent directly to OP instead of newsgroup) -- DF.