[studxml-users] problem with choosing content model at runtime

Boris Kolpackov boris at codesynthesis.com
Mon Dec 16 06:58:49 EST 2019


Gábor Balló <kvantumbit at gmail.com> 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:
> 
> <object>
>   <item>text1</item>
>   <item>text2</item>
>   <item>
>       <object2>
>         <tag>text3</tag>
>       </object2>
>   </item>
>   <item>text5</item>
>   ...
>   ...
> </object>
> 
> 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 <item> element has varying content model. So you
will need to do any necessary validation manually.



More information about the studxml-users mailing list