Here is what I tried:

r.xml:

<e xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:noNamespaceSchemaLocation="r.xsd"/>

r.xsd:

<schema xmlns="http://www.w3.org/2001/XMLSchema";>
 <element name="e">
  <complexType>
   <attribute name="a" fixed="v"/>
  </complexType>
 </element>
</schema>

code: the only modification:
     document = parser.parse(new InputSource((Reader)inputs));
to
     Document doc = parser.parse("file:///d:/r.xml");

And at the end, the value of "serviceName" is "v", the fixed value of
attribute "a". So there must be something else that affects your result.
Could you try my xml/xsd files?

Cheers,
Sandy Gao
Software Developer, IBM Canada
(1-905) 413-3255
[EMAIL PROTECTED]



                                                                                       
                       
                    hrout@pershing                                                     
                       
                    .com                 To:     [EMAIL PROTECTED]           
                       
                                         cc:     [EMAIL PROTECTED]                  
                       
                    03/04/2002           Subject:     noNamespaceSchemaLocation 
Problem with Xerces-J 2.0.0 / 
                    07:12 PM              Xerces 2.0.1 Release                         
                       
                    Please respond                                                     
                       
                    to                                                                 
                       
                    xerces-j-dev                                                       
                       
                                                                                       
                       
                                                                                       
                       



Hi All,

Today I downloaded XercesJ 2.0.1 and implemented my application with it. I
have a problem with both the versions of XercesJ-2.0.0 and XercesJ-2.0.1.

Problem:
     I am using XercesJ-2.0.0/XercesJ-2.0.1 (Implementing JAXP). I am using
DOM Parser to parse an xml instance validating against a schema and using
noNamespaceSchemaLocation. I have a fixed attribute in the schema. But
while parsing, the parser does not load the fixed attribute value into the
instance document.

(Note:  With targetNameSpace and externalSchemaLocation property the parser
loads the fixed attribute.)

XML Instance Used:

     <request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

     xsi:noNamespaceSchemaLocation="http://host/schemas/schema.xsd";>
     .......
     .......
     </request>

Schema Used:

     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:pct="
http://host/location";>
     <xsd:import namespace="http://host/location"; schemaLocation="
http://host/schemas/someSchema.xsd"/>
     .....
     ...
     <xsd:attribute name="name" type="xsd:string" fixed="SERVICE_NAME" />
     ...
     ....
     </xsd:schema>

Code Used:

     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     factory.setIgnoringElementContentWhitespace(true);
     factory.setValidating(true);
     factory.setNamespaceAware(true);
     factory.setAttribute("
http://java.sun.com/xml/jaxp/properties/schemaLanguage",";
http://www.w3.org/2001/XMLSchema";);

     //   I dont use the following property as it does not help for my
problem
     //   factory.setAttribute("
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
", "schema.xsd");

     DocumentBuilder parser = factory.newDocumentBuilder();
     document = parser.parse(new InputSource((Reader)inputs));

     Element root   = doc.getDocumentElement();
     NodeList nl = root.getChildNodes();
     NamedNodeMap attrs = root.getAttributes();
     String serviceName = "";
     if (attrs.getNamedItem("name") != null)  // Parser does not recognise
this fixed attribute from Schema
          serviceName = attrs.getNamedItem("name").getFirstChild
().getNodeValue();


Is there any other property to be set? Or Is there any work around to this
problem? Or am I making any mistake here in my implementation?

Any suggestion is highly appreciated.

Thanks and regards.
Haladhar


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to