[xml] (Hacky) XML includes



Hi

I've recently started dabbling with reading some XML files that have an
unusual include mechanism.  They look somewhat like this:

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <SomeElement>
      <include file="folder/anotherfile.xml"/>
      ...
    </SomeElement>

As an example for an included file:

  <AnElement>
    blah
  </AnElement>

  <AnotherElement>
    blah
  </AnotherElement>

I started off by writing a SAX parser, and the call to the first
document succeeded.  Inside the handler, I catch the include and
recursively parse again from there.  The thing is, at this point,
xmlSAXParseFile() triggers an error:

  Extra content at the end of the document

That makes sense (it appears to only expect one element), but I'm really
not sure how to counter this situation (I'm completely new to XML
parsing).  Am I going about this the right way?  My one big fear at the
moment is as to whether xmlSAXParseFile() is truly re-entrant.  That
aside, I also need to ensure that the AnElement and AnotherElement
elements are treated as sub-elements of SomeElement.  Is SAX even what
what I want to use in this circumstance?  The DOM would probably be more
appropriate for what I'm trying to do, it just appeared that SAX was
better suited to this kind of hacky include mechanism -- maybe there's a
mechanism within the DOM for this?

Thanks,
- Mab




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]