You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by mmfive <mm...@netspace.net.au> on 2003/04/18 10:51:53 UTC

Using Namespaces with Xerces-J-2.4.0

Hi All,

         I'm new to XML, so please excuse me if this sounds trival. I'm
using Namespces and I have a default namespace plus another two. When I usse
the Dom.Writer from the DOM samples from the Apache web site. I get the
following errors. I'm not sure why I'm getting them, what do I have to do to
my xml file to fix it?

 

[Error] Student1.xml:7:47: Attribute "xmlns:Sem" must be declared for
element type "Student1".

[Error] Student1.xml:7:47: Attribute "xmlns:Per" must be declared for
element type "Student1".

[Error] Student1.xml:7:47: Attribute "xmlns" must be declared for element
type "Student1".

 

 

The command I'm using with DTD is:

 

java dom.Writer -v Student1.xml > Student2-dtd.xml

 

My XML file is listed below.

 

<?xml version='1.0' encoding='utf-8' ?>

 

<!DOCTYPE Student1 SYSTEM "Amend.dtd">

 

<Student1 xmlns:Sem='http://www.mastrocinque.com/Semester'

          xmlns:Per='http://www.mastrocinque.com/Permanent'

          xmlns='http://www.mastrocinque.com'>

          

      <PersonDetails InterStudent = 'No' ApprenticeTrainee = 'Yes'>

            <StudentNumber>8812209</StudentNumber>        

            <FamilyName>Mastrocinque</FamilyName>  

            <GivenOtherNames>Jenny</GivenOtherNames>

            <GivenOtherNames>Harry</GivenOtherNames>

            <CourseTitle>Masters of Information Technology in Internet
Devlopment</CourseTitle>

      </PersonDetails>

 

      <ChangeOfNameOrTitle AmendDateOfBirth = '07/06/2970' Date =
'18/04/2003' Title = 'Mr'>

        <NewFamilyName>Sambucco</NewFamilyName>

        <NewGivenOtherNames>Jack</NewGivenOtherNames>        

      </ChangeOfNameOrTitle>

 

      <ChangeOfAddress>

        <Sem:SemesterAddress>                    

           <Sem:NumberOfStreet>45 McKean Street</Sem:NumberOfStreet>

           <Sem:SuburbOrTown>North Fitzroy</Sem:SuburbOrTown>

        </Sem:SemesterAddress>

        

        <Per:PermanentAddress>

           <Per:NumberOfStreet>86 Richardson Street</Per:NumberOfStreet>

           <Per:SuburbOrTown>North Carlton</Per:SuburbOrTown>

        </Per:PermanentAddress>

      </ChangeOfAddress>

 

</Student1>

 

My DTD file is

 

<!-- 'Amend.dtd' -->

 

<!ELEMENT Student1 (PersonDetails, ChangeOfNameOrTitle?, ChangeOfAddress)> 

 

<!-- Person Deatils -->

 

<!ELEMENT PersonDetails (StudentNumber, FamilyName, GivenOtherNames*,
CourseTitle)>

<!ATTLIST PersonDetails 

   InterStudent       (Yes | No | YES | NO) #REQUIRED

   ApprenticeTrainee  (Yes | No | YES | NO) #REQUIRED >

   

<!ELEMENT StudentNumber (#PCDATA) >

   

<!ELEMENT FamilyName (#PCDATA) > 

 

<!ELEMENT GivenOtherNames (#PCDATA) > 

 

<!ELEMENT CourseTitle (#PCDATA) > 

 

<!-- Change of name or title -->

 

<!ELEMENT ChangeOfNameOrTitle (NewFamilyName, NewGivenOtherNames*)>

<!ATTLIST ChangeOfNameOrTitle

   Title       (Dr | DR | Mr | MR | Mrs | MRS | Miss | MISS | Ms | MS)
#REQUIRED

   Date              CDATA #REQUIRED 

   AmendDateOfBirth  CDATA #IMPLIED >

   

<!ELEMENT NewFamilyName (#PCDATA)>

   

<!ELEMENT NewGivenOtherNames (#PCDATA)>

 

<!-- Change of Address -->

 

<!ELEMENT ChangeOfAddress (Sem:SemesterAddress, Per:PermanentAddress)>

 

<!-- Semester Address -->

 

<!ELEMENT Sem:SemesterAddress (Sem:NumberOfStreet, Sem:SuburbOrTown)>

 

<!ELEMENT Sem:NumberOfStreet (#PCDATA)>

 

<!ELEMENT Sem:SuburbOrTown (#PCDATA)>

 

<!-- Permanent Address -->

 

<!ELEMENT Per:PermanentAddress (Per:NumberOfStreet, Per:SuburbOrTown)>

 

<!ELEMENT Per:NumberOfStreet (#PCDATA)>

 

<!ELEMENT Per:SuburbOrTown (#PCDATA)>


Re: Using Namespaces with Xerces-J-2.4.0

Posted by Joseph Kesselman <ke...@us.ibm.com>.
DTDs predate namespaces, and don't consider them to be different from any 
other attribute. To use namespace declarations in a DTD-validated 
document, the DTD must be written to allow those attributes at the 
relevant points. Yes, this is a major nuisance, and it means you must use 
the specific prefix the DTD expects.

The only good solution is to validate against schemas rather than DTDs. 
Schemas are namespace-aware.

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more. 
"may'ron DaroQbe'chugh vaj bIrIQbej"  ("Put down the squeezebox and nobody 
gets hurt.")