Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39676
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: how to detect two or more roots in xml |
| Date | 2021-02-25 15:29 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <s18c88$c91$1@dont-email.me> (permalink) |
| References | <89601b6a-6ad6-4700-bf59-e9640b3ebafdn@googlegroups.com> |
On 2021-02-23 18:22, mike wrote: > Hi, > > I will have files like: > > <get> > <filter> > <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf"> > <system> > <security> > <user-params> > <local-user> > <user> > <user-name /> <!-- selection node in context A --> > </user> > </local-user> > </user-params> > </security> > </system> > </configure> > <state xmlns="urn:nokia.com:sros:ns:yang:sr:state"> > <system> > <security> > <user-params> > <local-user> > <user> > <attempted-logins /> <!-- selection node in context B --> > </user> > </local-user> > </user-params> > </security> > </system> > </state> > </filter> > </get> > > I will need to parse to xml: > > <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf"> > <system> > <security> > <user-params> > <local-user> > <user> > <user-name /> <!-- selection node in context A --> > </user> > </local-user> > </user-params> > </security> > </system> > </configure> > <state xmlns="urn:nokia.com:sros:ns:yang:sr:state"> > <system> > <security> > <user-params> > <local-user> > <user> > <attempted-logins /> <!-- selection node in context B --> > </user> > </local-user> > </user-params> > </security> > </system> > </state> > > 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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
how to detect two or more roots in xml mike <mikaelpetterson@hotmail.com> - 2021-02-23 09:22 -0800
Re: how to detect two or more roots in xml Arne Vajhøj <arne@vajhoej.dk> - 2021-02-23 21:27 -0500
Re: how to detect two or more roots in xml mike <mikaelpetterson@hotmail.com> - 2021-02-24 00:33 -0800
Re: how to detect two or more roots in xml Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2021-02-25 15:29 +0100
csiph-web