animal.xsd
-----------
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="animal" xmlns:animal="animal" 
xmlns="http://www.w3.org/2001/XMLSchema"; elementFormDefault="qualified">
<element name="PhysicalInfo" type="animal:PhysicalInfoType"/>
<complexType name="PhysicalInfoType">
<sequence>
    <element name="Name" type="string" />
    <element name="Colour" type="string" />
    <element name="LivesOn" type="string" />
</sequence>
</complexType>
</schema>


dog.xsd
---------
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="dog" xmlns:animal="animal" xmlns:dog= "dog" 
xmlns="http://www.w3.org/2001/XMLSchema"; elementFormDefault="unqualified">
<import namespace="animal" schemaLocation="animal.xsd"/>
<complexType name="DogPhysicalInfoType">
<sequence>
<element ref="animal:PhysicalInfo"/>
</sequence>
<attribute name="Breed" type="string" use="required"/>
</complexType>
<element name="DogPhysicalInfo" type="dog:DogPhysicalInfoType"/>
</schema>


DogTest.java
---------------
import org.exolab.castor.xml.Marshaller;
import java.io.StringWriter;

public class DogTest
{
  public static void main (String[] args) {
    try {
     
      DogPhysicalInfo dpi = new DogPhysicalInfo();
      PhysicalInfo pi = new PhysicalInfo();
      pi.setName("Ipkis");
      pi.setColour("Black");
      pi.setLivesOn("Land");
      dpi.setPhysicalInfo(pi);
      dpi.setBreed("BullDog");
   
      StringWriter swt = new StringWriter();
      Marshaller marshaller = new Marshaller(swt);
      marshaller.setNSPrefixAtRoot(true);
      marshaller.setNamespaceMapping("animal", "animal");
      marshaller.setNamespaceMapping("dog", "dog");
      marshaller.marshal(dpi);
      System.out.println(swt.toString());
    } catch (Exception e) {
      e.printStackTrace();
    } // end of try-catch
  } // end of main ()
}

Program output
-----------------
<?xml version="1.0"?>
<dog:DogPhysicalInfo Breed="BullDog" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:animal="animal" xmlns:dog="dog">   
    <dog:PhysicalInfo>
        <animal:Name>Ipkis</animal:Name>
        <animal:Colour>Black</animal:Colour>
        <animal:LivesOn>Land</animal:LivesOn>
    </dog:PhysicalInfo>
</dog:DogPhysicalInfo>

My question is, shouldnt the marshalled output have the namespace 
"animal" for "PhysicalInfo" element?
Why does it have the namespace "dog"?

Thanks,
Pratibha

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to