You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Rocky Raccoon <rr...@bigfoot.com> on 2000/05/23 01:27:29 UTC

Cyclic Dependency in a DTD

I am using the XML4C Parser to auto-generate an XML File
from a DTD.

For eg.
If there is 
<!ELEMENT A (B|C)>
I put the first one B inside A.
If the DTD specifies One or more occurances of an element,
I choose one occurance.

I use all the undocumented stuff to get the parsed contents of the
DTD.
[ for eg. 
	const ContentSpecNode* first = curNode->getFirst();
	const ContentSpecNode* second = curNode->getSecond();
	etc 
Something similiar to what the getFormattedContentModel does ]

Now everything works fine, except if there is a cyclic dependency.

ie.

<!ELEMENT A (A*, B)>

Here I get into an infinite loop.

This I can solve by choosing zero occurance of A inside A.

But another case is more complex.

<!ELEMENT A (A | B)>
This gets difficult for me to detect, that I am in an infinite
recursion.

Especially in a more complex case, where A is not directly inside A
but at a much deeper level.
Does anyone have an easy way to resolve this.

Re: Cyclic Dependency in a DTD

Posted by Dean Roddey <dr...@charmedquark.com>.
Use a stack of unsigned ints. Every time you 'enter' another element, push
its element id on the stack. When you exit each level, pop it off. Each time
you are about to process another element, search back up the stack and see
if that element id is there already. If so, you have hit a recursive
definition, no matter how many levels away the recursion is.

--------------------------
Dean Roddey
The CIDLib Class Libraries
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com

"Give me immortality, or give me death"

----- Original Message -----
> I am using the XML4C Parser to auto-generate an XML File
> from a DTD.
>
> For eg.
> If there is
> <!ELEMENT A (B|C)>
> I put the first one B inside A.
> If the DTD specifies One or more occurances of an element,
> I choose one occurance.
>
> I use all the undocumented stuff to get the parsed contents of the
> DTD.
> [ for eg.
> const ContentSpecNode* first = curNode->getFirst();
> const ContentSpecNode* second = curNode->getSecond();
> etc
> Something similiar to what the getFormattedContentModel does ]