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 "Ing. Hans Pesata" <hp...@chello.at> on 2001/09/02 13:04:53 UTC

Include XML-files

Hi !

I know this is not a typical XERCES-related question,
but I would like to know, if and how it is possible to include
XML-files with other XM-files ?!

I read about external entities, but these must be defined with a DTD
and not within my XML-file ?!

I am currently working on a project which will be using XERCES C++ using
XML-files with external DTDs
and (hopefully) possible includes.

If this is possible, how can I achieve this with XERCES ?
I will be using a SAX/SAX2 parser within my project.

Any help with this would be greatlya apprecited,
thanx in advance!

Regards,
Hans Pesata



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: AW: Include XML-files

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Ing. Hans Pesata" <hp...@chello.at> writes:

> Hi !
> 
> // You can include dtd files in the same way.
> // Like this:
> //
> // <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
> //
> // <!DOCTYPE configuration SYSTEM "test.dtd"
> // [
> // 	<!ENTITY xmlfile SYSTEM "test1.xml">
> // 	<!ENTITY % dtdfile SYSTEM "test1.dtd">
> //       %dtdfile;
> // ]>
> //
> // <configuration>
> //
> // 	<sections>
> // 		<section name="Default-Values">
> // 			<file>&xmlfile;</file>
> // 		</section>
> // 	</sections>
> //
> // </configuration>
> //
> // The entity dtdfile will be expanded immediatly when it is seen
> // and thereby
> // loading the file test1.dtd during the DTD parsing.
> // Note this is pure "this should work". I have not tested it myself.
> 
> the only problem is see with this approach is, that the DTD-file is
> not bound to the included XML-file and so I cant make sure, that the
> included XML-file is 100% validated correctly.


This is incorrect. The function of the entities is just so you can
store the definitions in an external file. So the behavior is
identical to what you would see if you had placed the contents of
dtdfile directly in the internal subset, and xmlfile in the
text. Therefore the contents of xmlfile are validated using the
combined contents of test1.dtd and dtdfile. That is as tight a binding
as you can get.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


AW: AW: Include XML-files

Posted by "Ing. Hans Pesata" <hp...@chello.at>.
Hi !

Thanx a lot for the replies !

// If you want it that finely controlled, you have to parse the files
// separately and then combine the DOM trees (import one into the other).
// Ciao, Jürgen

I will be using SAX, because it fits better into the approach my app uses.

// This is incorrect. The function of the entities is just so you can
// store the definitions in an external file. So the behavior is
// identical to what you would see if you had placed the contents of
// dtdfile directly in the internal subset, and xmlfile in the
// text. Therefore the contents of xmlfile are validated using the
// combined contents of test1.dtd and dtdfile. That is as tight a binding
// as you can get.
// jas.

I understand that this is just somekind of splitting the whole
XML/DTD-data into several parts.

What I meant to say was, that there is no exact binding of
TEST1.XML with TEST1.DTD, TEST1.XML is parsesd according to the
mixed information from TEST.DTD and TEST1.DTD.

So I can define elements from TEST.DTD within TEST1.XML, for example.

But probably using namespaces, as Erik suggested, will do the trick.
I have to look into this.

Best regards,
Hans Pesata



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: AW: Include XML-files

Posted by Juergen Hermann <jh...@web.de>.
On Tue, 4 Sep 2001 09:46:22 +0200, Ing. Hans Pesata wrote:

>the only problem is see with this approach is, that the DTD-file
>is not bound to the included XML-file and so I cant make sure,
>that the included XML-file is 100% validated correctly.

If you want it that finely controlled, you have to parse the files 
separately and then combine the DOM trees (import one into the other).


Ciao, Jürgen



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


AW: Include XML-files

Posted by "Ing. Hans Pesata" <hp...@chello.at>.
Hi !

// You can include dtd files in the same way.
// Like this:
//
// <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
//
// <!DOCTYPE configuration SYSTEM "test.dtd"
// [
// 	<!ENTITY xmlfile SYSTEM "test1.xml">
// 	<!ENTITY % dtdfile SYSTEM "test1.dtd">
//       %dtdfile;
// ]>
//
// <configuration>
//
// 	<sections>
// 		<section name="Default-Values">
// 			<file>&xmlfile;</file>
// 		</section>
// 	</sections>
//
// </configuration>
//
// The entity dtdfile will be expanded immediatly when it is seen
// and thereby
// loading the file test1.dtd during the DTD parsing.
// Note this is pure "this should work". I have not tested it myself.

thanx for the hint, it works.

the only problem is see with this approach is, that the DTD-file
is not bound to the included XML-file and so I cant make sure,
that the included XML-file is 100% validated correctly.

I understand, that the 2nd DTD is just loaded and not connected to the
included XML-file,
so the included XML-file could also contain elements of the 1st DTD, altough
they
are not valid within this file.

Is there a possibilty to connect the 2 files e.g. by placing the %dtdfile
somewhere else
within the XML-file ?

Regards,
Hans Pesata



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: Include XML-files

Posted by Erik Rydgren <er...@mandarinen.se>.
You can include dtd files in the same way.
Like this:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

<!DOCTYPE configuration SYSTEM "test.dtd"
[
	<!ENTITY xmlfile SYSTEM "test1.xml">
	<!ENTITY % dtdfile SYSTEM "test1.dtd">
      %dtdfile;
]>

<configuration>

	<sections>
		<section name="Default-Values">
			<file>&xmlfile;</file>
		</section>
	</sections>

</configuration>

The entity dtdfile will be expanded immediatly when it is seen and thereby
loading the file test1.dtd during the DTD parsing.
Note this is pure "this should work". I have not tested it myself.

Good luck.

Erik Rydgren
Mandarinen systems AB
Sweden


-----Original Message-----
From: Ing. Hans Pesata [mailto:hpesata@chello.at]
Sent: den 3 september 2001 13:41
To: xerces-c-dev@xml.apache.org
Subject: AW: Include XML-files


Hi !

I realized, that it is not possible to use external entities within
attributes,
so I triedusing the include for my external XML-file within an element
and this works.

Another thing I realized is, that I cant use a DTD within
the included XML-file, that means I just can access/use elements already
declared in the 1st DTD ?!

my goal was to use an DTD within the included XML-file too.

Is there any possibility to achieve this ?

Regards,
Hans Pesata

-------------------------------
TEST.DTD
-------------------------------

<!ELEMENT	configuration (sections?)>

<!ELEMENT	sections (section*)>
<!ELEMENT	section (file, entries?)>
<!ATTLIST	section
		name	CDATA	#REQUIRED>
<!ELEMENT	file ANY>

<!ELEMENT	entries (entry*)>
<!ELEMENT	entry EMPTY>
<!ATTLIST	entry
		name	CDATA	#REQUIRED>

-------------------------------
TEST.XML
-------------------------------

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

<!DOCTYPE configuration SYSTEM "test.dtd"
[
	<!ENTITY xmlfile SYSTEM "test1.xml">
]>

<configuration>

	<sections>
		<section name="Default-Values">
			<file>&xmlfile;</file>
		</section>
	</sections>

</configuration>

-------------------------------
TEST1.XML
-------------------------------

<entries>
	<entry name="1"/>
	<entry name="2"/>
	<entry name="3"/>
</entries>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


AW: Include XML-files

Posted by "Ing. Hans Pesata" <hp...@chello.at>.
Hi !

I realized, that it is not possible to use external entities within
attributes,
so I triedusing the include for my external XML-file within an element
and this works.

Another thing I realized is, that I cant use a DTD within
the included XML-file, that means I just can access/use elements already
declared in the 1st DTD ?!

my goal was to use an DTD within the included XML-file too.

Is there any possibility to achieve this ?

Regards,
Hans Pesata

-------------------------------
TEST.DTD
-------------------------------

<!ELEMENT	configuration (sections?)>

<!ELEMENT	sections (section*)>
<!ELEMENT	section (file, entries?)>
<!ATTLIST	section
		name	CDATA	#REQUIRED>
<!ELEMENT	file ANY>

<!ELEMENT	entries (entry*)>
<!ELEMENT	entry EMPTY>
<!ATTLIST	entry
		name	CDATA	#REQUIRED>

-------------------------------
TEST.XML
-------------------------------

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

<!DOCTYPE configuration SYSTEM "test.dtd"
[
	<!ENTITY xmlfile SYSTEM "test1.xml">
]>

<configuration>

	<sections>
		<section name="Default-Values">
			<file>&xmlfile;</file>
		</section>
	</sections>

</configuration>

-------------------------------
TEST1.XML
-------------------------------

<entries>
	<entry name="1"/>
	<entry name="2"/>
	<entry name="3"/>
</entries>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


AW: Include XML-files

Posted by "Ing. Hans Pesata" <hp...@chello.at>.
Hi !

// Actually, this is a very typical question, and yes, you use external
// entities. Instead of defining them in your DTD (i.e. the external
// subset), you use the internal subset within your XML document:
//
// <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
// <!DOCTYPE classes SYSTEM 'classes.dtd' [
//   <!ENTITY Person SYSTEM "Person.xml" >
//   <!ENTITY Security SYSTEM "Security.xml" >
//   <!ENTITY Audit SYSTEM "Audit.xml" >
//   <!ENTITY Organization SYSTEM "Organization.xml" >
//   <!ENTITY SecurityGroup SYSTEM "SecurityGroup.xml" >
//   <!ENTITY Contact SYSTEM "Contact.xml" >
//
// ]>
// <classes>
// &Person;
// &Security;
// &Audit;
// &Organization;
// &SecurityGroup;
// &Contact;
//
// </classes>
//
// HTH,

Thanx for your reply!

I need a slightly different approach, than the one you suggested.
I need to use the entity-value in an attribute of another object than the
root-object:

-------------------------------------------
TEST.DTD
-------------------------------------------

<!ELEMENT	configuration (sections?)>

<!ELEMENT	sections (section*)>
<!ELEMENT	section EMPTY>
<!ATTLIST	section
			name	  CDATA	#REQUIRED
			xmlfile ENTITY	#REQUIRED>

-------------------------------------------
TEST.XML
-------------------------------------------

<?xml version="1.0" standalone="no"?>

<!DOCTYPE configuration SYSTEM "test.dtd"
[
	<!ENTITY xmlfile SYSTEM "section.xml">
]>

<configuration>

	<sections>
		<section name="Default-Values" xmlfile="xmlfile"/>
	</sections>

</configuration>

-------------------------------------------

this doesnt work, because the entity isnt defined within the DTD...

Best regards,
Hans Pesata



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Include XML-files

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Ing. Hans Pesata" <hp...@chello.at> writes:

> I know this is not a typical XERCES-related question,
> but I would like to know, if and how it is possible to include
> XML-files with other XM-files ?!
> 
> I read about external entities, but these must be defined with a DTD
> and not within my XML-file ?!

Actually, this is a very typical question, and yes, you use external
entities. Instead of defining them in your DTD (i.e. the external
subset), you use the internal subset within your XML document:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE classes SYSTEM 'classes.dtd' [
  <!ENTITY Person SYSTEM "Person.xml" >
  <!ENTITY Security SYSTEM "Security.xml" >
  <!ENTITY Audit SYSTEM "Audit.xml" >
  <!ENTITY Organization SYSTEM "Organization.xml" >
  <!ENTITY SecurityGroup SYSTEM "SecurityGroup.xml" >
  <!ENTITY Contact SYSTEM "Contact.xml" >

]>
<classes>
&Person;
&Security;
&Audit;
&Organization;
&SecurityGroup;
&Contact;

</classes>
 
HTH,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org