0

I'm trying to write an xsd that I can insert another xml (that I have an xsd for) file into it at runtime. I don't want to import the xsd definitions so that I can reference it - I want to have a placeholder for an xml file so that at runtime it gets treated as if it is part of the xml doc.

What I am trying is the following:

<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<!DOCTYPE doc [
<!ENTITY FilterPassbandDefinitions PUBLIC "passband-lookup.xml" "">
]>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="pathmapping" xmlns:pm="pathmapping">
<xs:element name="pathMapping">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="paths" type="pm:Path" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="technologies" type="pm:Technology" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="devices" type="pm:Device" minOccurs="1" maxOccurs="unbounded" />
            <xs:element name="arrayPanel" type="pm:ArrayPanel" minOccurs="1" maxOccurs="unbounded" />
            &FilterPassbandDefinitions;
        </xs:sequence>
    </xs:complexType>
</xs:element>

But when trying to validate the xsd I get the following complaint: "No more pseudo attributes are allowed on the 'standalone = "no" ' " component.

If I remove the 'standalone = "no" ' then I get the following: "A DOCTYPE is not allowed in content"

Thanks in advance.

EDIT 03/21/18:

I have these two xml files and eclipse doesn't seem to be complaining. It is based on this link: Can we import XML file into another XML file?

I have the following:

otherFile.xml

<?xml version="1.0" encoding="UTF-8" ?>
<doc>
  <foo>
    <bar><baz>this is my content</baz></bar>
  </foo>
</doc>

test.xml:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE doc [
<!ENTITY otherFile SYSTEM "otherFile.xml">
]>
<doc>
  <foo>
    <bar>&otherFile;</bar>
  </foo>
</doc>

What I'd like to do now is define an xsd for these files.

georges
  • 175
  • 4
  • 17

1 Answers1

0

This one had me quite confused, but your entity declaration has a system ID of "", which is a reference to the current document, so the entity reference &FilterPassbandDefinitions is pulling in a copy of the current document recursively, and that's including a DOCTYPE declaration at a point where it isn't allowed. If you change the system ID to point to an appropriate document, then this should work. (Though whether it actually achieves what you're trying to do is another question -- I don't think I understand what you are trying to do.)

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • What should i put for the system id? and how would I reference it? What I want to do is define an xsd (and an xml[call it xml1] based off of that xsd) that includes an external xml[call it xml2] file so at runtime i can drop in a different external xml2 file without having to change xml1 file - does that clear things up or am i still not explaining well enough – georges Mar 18 '18 at 14:40
  • I want to do something like this: https://stackoverflow.com/questions/5121052/can-we-import-xml-file-into-another-xml-file but I want to have an xsd defined - can i do that? – georges Mar 18 '18 at 16:25
  • Firstly, in the schema you can include a wildcard (xs:any, perhaps with processContents="strict") to allow content that isn't defined in the schema. Secondly, in the XML instance you can use external entities or XInclude to include content from a different file. You seem to be mixing up these mechanisms. – Michael Kay Mar 18 '18 at 18:01
  • Do you think you could provide an example of defining and xsd and an xml where i reference an external xml file inside of it? – georges Mar 21 '18 at 00:28
  • I can't provide an example that will help you without a better understanding of your requirement. – Michael Kay Mar 21 '18 at 09:39
  • If you could look at the edit - I posted a working example of two xml files with one referencing the other - what I'd like to do is define a schema for both of them. – georges Mar 22 '18 at 00:13