MattEvans 473 Veteran Poster

I'm working with a strange schema of my own invention, it has a requirement that certain structures can only contain other structures; but also that those structures can contain 'filters' that optionally sit between structures-in-structures, i.e, this would be a valid document fragment:

<entity>
  <material name="mat1">
    <texture component="ambient" src="somepng.png"/>
  </material>
  <model src="somemodel.obj"/>
</entity>

as would this:

<entity>
  <material name="mat1">
    <texture component="ambient" src="somepng.png"/>
  </material>
  <dynamic-filter input="level-of-detail">
    <constant-filter-function value="0.5" function="LTE">
      <model src="somemodel_lodetail.obj"/>
    </constant-filter-function>
    <filter-else>
      <model src="somemodel_hidetail.obj"/>
    </filter-else>
  </dynamic-filter>
</entity>

but this would not:

<entity>
  <material name="mat1">
    <texture component="ambient" src="somepng.png"/>
  </material>
<!-- texture is not allowed as a substructure of entity; only can go in material-->
  <texture component="ambient" src="somepng.png"/>
  <model src="somemodel.obj"/>
</entity>

and nor would this:

<entity>
  <material name="mat1">
    <texture component="ambient" src="somepng.png"/>
  </material>
  <dynamic-filter input="level-of-detail">
    <constant-filter-function value="0.5" function="LTE">
<!-- texture is not allowed as a substructure of entity; only can go in material-->
      <texture component="ambient" src="somepng.png"/>
      <model src="somemodel_lodetail.obj"/>
    </constant-filter-function>
    <filter-else>
      <model src="somemodel_hidetail.obj"/>
    </filter-else>
  </dynamic>
</entity>

Now... any complex structure can have any number of filters ( a complex structure doesn't have a src or a type, i.e. it is an xml structure ), and filters inside filters inside filters; but those filters can only 'yield' structures that can go into the parent structure directly.. Since I have more complex structures than 'entity'; and quite a few different filter classes I was stuck with my schema design, either have an #any content within the filter end nodes ( constant-filter-function / filter-else / etc ), which makes the schema about as useful as the DTD, or rewrite the whole filter system for every complex structure.. I messed about somewhat with <xs:redefine >, but it seems that schema validators ( correctly ) collect all redefines into some global pool rather than applying them only within the context of a single <xs:include or xs:import>'ed document.

Anyway.. messing with DTDs + schema, I came accross this wierdness, it has certain potential, but only if it's actually legal, I have tested it with a validator, xmllint, but it seems wrong to me:

File: test_schema.xml

<?xml version="1.0"?>
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd" [
	<!ENTITY name "test">
	<!ENTITY test_pull SYSTEM "test_pull.xml">
]>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
	 &test_pull;
</schema>

File: test_pull.xml

<element name="&name;" xmlns="http://www.w3.org/2001/XMLSchema"/>

File: test_in.xml

<?xml version="1.0"?>
<test>
	
</test>

running xmllint with test_in.xml against test_schema.dtd:

[threed@localhost schemas]$ xmllint --noout --schema test_schema.xml 
                            test_in.xml
test_in.xml validates

The reason I'm questioning its legality; is that xmllint won't let me put any DTD or xml PI on the test_pull.xml file, and it seems to suck in the &name; entity from test_schema.xsd... everything i've seen in XML thus far suggests that entities are document-bound. Are they? I can use this method, if it's legal, by defining filter in an single deep xs:element, with a reference to some xs:group named with a prefix of Entity, Material etc, based on the &name; entity.... Is it legal though? Alternatively, is there a way to express this constraint in 'unadulterated' w3c xml schema, without rewriting/copy-paste-replacing huge chunks of the schema?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.