From kvantumbit at gmail.com Fri Dec 13 06:24:07 2019 From: kvantumbit at gmail.com (=?UTF-8?B?R8OhYm9yIEJhbGzDsw==?=) Date: Fri Dec 13 06:27:29 2019 Subject: [studxml-users] problem with choosing content model at runtime Message-ID: Hi! I just started to use libstudxml for a project. I think it is very straightforward and easy to use. However there is one thing I could not solve in any way so far. I am trying to parse an XML like this: text1 text2 text3 text5 ... ... My problem is that the first two item elements would use simple content model, but the third is complex. There can be any number of item elements, this is just an example. Also I cannot assume that the complex item element will be the third one. It can appear anywhere in the list of item elements. Unfortunately I could not find a way to check, what does the next item element contain (text or other elements), so what content model should I use to parse it. Is there any way to do this with libstudxml? Thank you! Best regards, Gabor From boris at codesynthesis.com Mon Dec 16 06:58:49 2019 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 16 07:02:00 2019 Subject: [studxml-users] problem with choosing content model at runtime In-Reply-To: References: Message-ID: G?bor Ball? writes: > I just started to use libstudxml for a project. I think it is very > straightforward and easy to use. Thanks! > However there is one thing I could not solve in any way so far. I am > trying to parse an XML like this: > > > text1 > text2 > > > text3 > > > text5 > ... > ... > > > My problem is that the first two item elements would use simple > content model, but the third is complex. > There can be any number of item elements, this is just an example. > Also I cannot assume that the complex item element will be the third > one. It can appear anywhere in the list of item elements. > > Unfortunately I could not find a way to check, what does the next item > element contain (text or other elements), so what content model should > I use to parse it. The content model validation is an "extra convenience" that is built on top of the plain parsing support. This, however, requires you to know the expected content type ahead of time (this is normally the case when you parse a vocabulary specified in XML Schema or similar, which is where the idea/terminology comes from). In your case, the element has varying content model. So you will need to do any necessary validation manually.