Validating NSXMLDocument with DTD that has ANY condition

  • Now that I can ready my NSXMLDocument I'm trying to validate it. The
    documents that I"m parsing are well defined, but one type of element
    <extension> should be able to hold any kind of valid XML content. But
    I'm not sure how to validate that, right now I'm getting errors from
    [NSXMLDocument validateAndReturnError] anytime I use an element name
    that isn't explicitly declared in my DTD. For example I get this error:

    NSError "No declaration for element applicationWillFinishLaunching
    No declaration for attribute class of element
    applicationWillFinishLaunching
    " Domain=NSXMLParserErrorDomain Code=1 UserInfo={
        NSLocalizedDescription = "No declaration for element
    applicationWillFinishLaunching\nNo declaration for attribute class of
    element applicationWillFinishLaunching\n";
    }

    In a document that has a <applicationWillFinishLaunching> element
    declared in the section that should allow ANY elements.

    Does anyone know what I need to do to validate my document, but let
    the children of one element type contain any valid XML?

    Thanks,
    Jesse

    Below I've included the sample XML file that gets the above
    validation error, and I've included the validating DTD below that.

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

    <?xml version="1.0" encoding="UTF-8"?>

    <plugin
    id="com.blocks.BPreferences"
    label="Preferences"
    version="1.0.0"
    info="Blocks Preferences">

    <requirement bundle="com.blocks.Blocks"/>
    <requirement bundle="com.blocks.BLifecycle"/>
    <requirement bundle="com.blocks.BUserInterface"/>

    <extension-point id="preferencePanes" />

    <extension point="com.blocks.BLifecycle.lifecycle">
      <applicationWillFinishLaunching class="BPreferencesController" />
    </extension>
    </plugin>

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

    <!ELEMENT plugin (requirement*, extension-point*, extension*)>
    <!ATTLIST plugin
    id CDATA #REQUIRED
    label CDATA #REQUIRED
    version CDATA #REQUIRED
    info CDATA #IMPLIED
    >

    <!ELEMENT requirement EMPTY>
    <!ATTLIST requirement
    bundle CDATA #REQUIRED
    version CDATA #IMPLIED
    optional (true | false) "false"
    >

    <!ELEMENT extension-point EMPTY>
    <!ATTLIST extension-point
    id CDATA #REQUIRED
    >

    <!ELEMENT extension ANY>
    <!ATTLIST extension
    point CDATA #REQUIRED
    >
  • Unfortunately, ANY means "any element in the DTD." You're probably
    trying to handle unknown elements, and I'm not aware of a solution for
    that. XML Schema (which libxml supports but NSXML doesn't) lets you
    skip all elements in a known namespace. If you wanted, you could
    validate the data with libxml before passing it to NSXML.

    -Steve

    BTW, a useful tool for debugging DTDs is xmllint:

    xmllint --dtdvalid plugin.dtd plugin.xml

    On 8/29/07, Jesse Grosjean <jesse...> wrote:
    > Now that I can ready my NSXMLDocument I'm trying to validate it. The
    > documents that I"m parsing are well defined, but one type of element
    > <extension> should be able to hold any kind of valid XML content. But
    > I'm not sure how to validate that, right now I'm getting errors from
    > [NSXMLDocument validateAndReturnError] anytime I use an element name
    > that isn't explicitly declared in my DTD. For example I get this error:
    >
    > NSError "No declaration for element applicationWillFinishLaunching
    > No declaration for attribute class of element
    > applicationWillFinishLaunching
    > " Domain=NSXMLParserErrorDomain Code=1 UserInfo={
    > NSLocalizedDescription = "No declaration for element
    > applicationWillFinishLaunching\nNo declaration for attribute class of
    > element applicationWillFinishLaunching\n";
    > }
    >
    > In a document that has a <applicationWillFinishLaunching> element
    > declared in the section that should allow ANY elements.
    >
    > Does anyone know what I need to do to validate my document, but let
    > the children of one element type contain any valid XML?
    >
    > Thanks,
    > Jesse
    >
    > Below I've included the sample XML file that gets the above
    > validation error, and I've included the validating DTD below that.
    >
    > ----------------------------------------------
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    >
    > <plugin
    > id="com.blocks.BPreferences"
    > label="Preferences"
    > version="1.0.0"
    > info="Blocks Preferences">
    >
    > <requirement bundle="com.blocks.Blocks"/>
    > <requirement bundle="com.blocks.BLifecycle"/>
    > <requirement bundle="com.blocks.BUserInterface"/>
    >
    > <extension-point id="preferencePanes" />
    >
    > <extension point="com.blocks.BLifecycle.lifecycle">
    > <applicationWillFinishLaunching class="BPreferencesController" />
    > </extension>
    > </plugin>
    >
    > ----------------------------------------------
    >
    > <!ELEMENT plugin (requirement*, extension-point*, extension*)>
    > <!ATTLIST plugin
    > id CDATA #REQUIRED
    > label CDATA #REQUIRED
    > version CDATA #REQUIRED
    > info CDATA #IMPLIED
    >>
    >
    > <!ELEMENT requirement EMPTY>
    > <!ATTLIST requirement
    > bundle CDATA #REQUIRED
    > version CDATA #IMPLIED
    > optional (true | false) "false"
    >>
    >
    > <!ELEMENT extension-point EMPTY>
    > <!ATTLIST extension-point
    > id CDATA #REQUIRED
    >>
    >
    > <!ELEMENT extension ANY>
    > <!ATTLIST extension
    > point CDATA #REQUIRED
    >>

    >
previous month august 2007 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today