| Using XSD API with DOM [message #55042] | 
Tue, 23 November 2004 10:20   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: ooi.de.ibm.com 
 
Hello, 
 
I am currently trying to use the xsd API with DOM to generate XML files  
which do not only contain the schema element.Is it possible to use these  
the xsd API and the DOM API together in the same Java Implementation? if  
not,how do i go about this situation?  
 
Thank you.
 |  
 |  
  | 
 | 
 | 
 | 
 | 
| Re: Using XSD API with DOM [message #55221 is a reply to message #55194] | 
Thu, 25 November 2004 06:51   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: merks.ca.ibm.com 
 
This is a multi-part message in MIME format. 
--------------060807050408030108000804 
Content-Type: text/plain; charset=ISO-8859-15; format=flowed 
Content-Transfer-Encoding: 7bit 
 
HT, 
 
When you call setElement with an element you constructed, it builds a  
model to reflects exactly what's in that element and it discards all the  
other information you might have set up that does not reflect what's in  
the element.  So your invalid blank element wipes out all the other  
settings you did.  If you are going to create a valid element manually,  
you need to make sure to use createElementNS to give it the right  
namespace and you'll need to create an xmlns declaration for that  
namespace. 
 
In this scenario, you should have done something like this: 
 
    Document document; 
    XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema(); 
    xsdSchema.setDocument(document); 
 
    xsdSchema.setTargetNamespace("http://www.eclipse.org/xsd/examples/createxsd"); 
 
    java.util.Map qNamePrefixToNamespaceMap = 
    xsdSchema.getQNamePrefixToNamespaceMap(); 
     qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(), 
    XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); 
    qNamePrefixToNamespaceMap.put("createxsd", 
    xsdSchema.getTargetNamespace()); 
    xsdSchema.updateElement(); 
 
I.e., give the schema the document you want it to use to create elements  
and let it do all the work of creating the DOM.  Failing that, create a  
correct DOM, set it to the schema, and then do other settings, which  
will write through to update the DOM.  (I would generally avoid using  
the null prefix for the schema for schema namespace, since that makes  
the null namespace inaccessible, if it's needed.) 
 
 
HT Ooi wrote: 
 
> Hi Ed, 
> 
> I'm tried using : 
> 
> Document document; 
> Element schemaElement = (Element) document.createElement("schema"); 
> document.appendChild(schemaElement); 
> XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema(); 
> 
> xsdSchema.setTargetNamespace("http://www.eclipse.org/xsd/examples/createxsd");  
> 
> java.util.Map qNamePrefixToNamespaceMap =  
> xsdSchema.getQNamePrefixToNamespaceMap(); 
>  qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(),  
> XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); 
> qNamePrefixToNamespaceMap.put("createxsd",  
> xsdSchema.getTargetNamespace()); 
> xsdSchema.setElement(schemaElement); 
> xsdSchema.updateElement(); 
> 
> but the output in my file is just : 
>  <?xml version="1.0" encoding="UTF-8" ?>  <schema /> 
> instead of using the above (writing schema directly into file )  i have : 
>  <?xml version="1.0" ?>  <xsd:schema  
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> 
> why is there a difference? 
> the reason i want to do this is because i am using WSDL4J to create  
> WSDLs and schema elements can only be represented as DOM elements. 
> 
> Thank you. 
> 
> 
> 
> 
> 
 
 
--------------060807050408030108000804 
Content-Type: text/html; charset=ISO-8859-15 
Content-Transfer-Encoding: 8bit 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
  <meta content="text/html;charset=ISO-8859-15" 
 http-equiv="Content-Type"> 
  <title></title> 
</head> 
<body bgcolor="#ffffff" text="#000000"> 
HT,<br> 
<br> 
When you call setElement with an element you constructed, it builds a 
model to reflects exactly what's in that element and it discards all 
the other information you might have set up that does not reflect 
what's in the element.
 |  
 |  
  | 
| Re: Using XSD API with DOM [message #592619 is a reply to message #55042] | 
Tue, 23 November 2004 10:28   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hee, 
 
I'm not sure I understand.  The XSD model uses DOM itself, so certainly  
XSD and DOM can be used in the same application.  The XSD model can be  
used to load a .wsdl file which contains embedded schemas, but I'm not  
sure if that is what you are driving at... 
 
 
Hee Tatt Ooi wrote: 
 
> Hello, 
> 
> I am currently trying to use the xsd API with DOM to generate XML  
> files which do not only contain the schema element.Is it possible to  
> use these the xsd API and the DOM API together in the same Java  
> Implementation? if not,how do i go about this situation? 
> Thank you. 
>
 |  
 |  
  | 
| Re: Using XSD API with DOM [message #592640 is a reply to message #55068] | 
Tue, 23 November 2004 11:04   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: ooi.de.ibm.com 
 
Hi, 
 
How do i use xsd and dom together? i mean can i convert my XSDSchema to a  
Element so i can write in into my wsdl? or when reading a wsdl using DOM ,  
how do i convert the schema Element into a XSDSchema instance.. 
 
Thanks. 
 
HT.
 |  
 |  
  | 
| Re: Using XSD API with DOM [message #592661 is a reply to message #55115] | 
Tue, 23 November 2004 12:32   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
This is a multi-part message in MIME format. 
--------------000308080106090905030907 
Content-Type: text/plain; charset=ISO-8859-15; format=flowed 
Content-Transfer-Encoding: 7bit 
 
HT, 
 
Have a look at org.eclipse.xsd.util.XSDPrototypicalSchema.  In  
particular, look at printComponent and createElement.  You probably will  
want to try registering the XSD resource factory to handle wsdl like this 
 
     resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put 
      ("wsdl", new XSDResourceFactoryImpl()); 
 
and then try loading a .wsdl file just as you would load a .xsd file... 
 
 
HT Ooi wrote: 
 
> Hi, 
> 
> How do i use xsd and dom together? i mean can i convert my XSDSchema  
> to a Element so i can write in into my wsdl? or when reading a wsdl  
> using DOM , how do i convert the schema Element into a XSDSchema  
> instance.. 
> 
> Thanks. 
> 
> HT. 
> 
 
 
--------------000308080106090905030907 
Content-Type: text/html; charset=ISO-8859-15 
Content-Transfer-Encoding: 8bit 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
  <meta content="text/html;charset=ISO-8859-15" 
 http-equiv="Content-Type"> 
</head> 
<body bgcolor="#ffffff" text="#000000"> 
HT,<br> 
<br> 
Have a look at org.eclipse.xsd.util.XSDPrototypicalSchema.
 |  
 |  
  | 
| Re: Using XSD API with DOM [message #592674 is a reply to message #55168] | 
Thu, 25 November 2004 04:22   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: ooi.de.ibm.com 
 
Hi Ed, 
 
I'm tried using : 
 
Document document; 
Element schemaElement = (Element) document.createElement("schema"); 
document.appendChild(schemaElement); 
XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema(); 
 
xsdSchema.setTargetNamespace("http://www.eclipse.org/xsd/examples/createxsd"); 
java.util.Map qNamePrefixToNamespaceMap =  
xsdSchema.getQNamePrefixToNamespaceMap(); 
 qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(),  
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); 
qNamePrefixToNamespaceMap.put("createxsd", xsdSchema.getTargetNamespace()); 
xsdSchema.setElement(schemaElement); 
xsdSchema.updateElement(); 
 
but the output in my file is just : 
  <?xml version="1.0" encoding="UTF-8" ?>  
  <schema />  
 
instead of using the above (writing schema directly into file )  i have : 
  <?xml version="1.0" ?>  
  <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" />  
 
why is there a difference?  
 
the reason i want to do this is because i am using WSDL4J to create WSDLs  
and schema elements can only be represented as DOM elements. 
 
Thank you.
 |  
 |  
  | 
| Re: Using XSD API with DOM [message #592685 is a reply to message #55194] | 
Thu, 25 November 2004 06:51   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
This is a multi-part message in MIME format. 
--------------060807050408030108000804 
Content-Type: text/plain; charset=ISO-8859-15; format=flowed 
Content-Transfer-Encoding: 7bit 
 
HT, 
 
When you call setElement with an element you constructed, it builds a  
model to reflects exactly what's in that element and it discards all the  
other information you might have set up that does not reflect what's in  
the element.  So your invalid blank element wipes out all the other  
settings you did.  If you are going to create a valid element manually,  
you need to make sure to use createElementNS to give it the right  
namespace and you'll need to create an xmlns declaration for that  
namespace. 
 
In this scenario, you should have done something like this: 
 
    Document document; 
    XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema(); 
    xsdSchema.setDocument(document); 
 
    xsdSchema.setTargetNamespace("http://www.eclipse.org/xsd/examples/createxsd"); 
 
    java.util.Map qNamePrefixToNamespaceMap = 
    xsdSchema.getQNamePrefixToNamespaceMap(); 
     qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(), 
    XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); 
    qNamePrefixToNamespaceMap.put("createxsd", 
    xsdSchema.getTargetNamespace()); 
    xsdSchema.updateElement(); 
 
I.e., give the schema the document you want it to use to create elements  
and let it do all the work of creating the DOM.  Failing that, create a  
correct DOM, set it to the schema, and then do other settings, which  
will write through to update the DOM.  (I would generally avoid using  
the null prefix for the schema for schema namespace, since that makes  
the null namespace inaccessible, if it's needed.) 
 
 
HT Ooi wrote: 
 
> Hi Ed, 
> 
> I'm tried using : 
> 
> Document document; 
> Element schemaElement = (Element) document.createElement("schema"); 
> document.appendChild(schemaElement); 
> XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema(); 
> 
> xsdSchema.setTargetNamespace("http://www.eclipse.org/xsd/examples/createxsd");  
> 
> java.util.Map qNamePrefixToNamespaceMap =  
> xsdSchema.getQNamePrefixToNamespaceMap(); 
>  qNamePrefixToNamespaceMap.put(xsdSchema.getSchemaForSchemaQN amePrefix(),  
> XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); 
> qNamePrefixToNamespaceMap.put("createxsd",  
> xsdSchema.getTargetNamespace()); 
> xsdSchema.setElement(schemaElement); 
> xsdSchema.updateElement(); 
> 
> but the output in my file is just : 
>  <?xml version="1.0" encoding="UTF-8" ?>  <schema /> 
> instead of using the above (writing schema directly into file )  i have : 
>  <?xml version="1.0" ?>  <xsd:schema  
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> 
> why is there a difference? 
> the reason i want to do this is because i am using WSDL4J to create  
> WSDLs and schema elements can only be represented as DOM elements. 
> 
> Thank you. 
> 
> 
> 
> 
> 
 
 
--------------060807050408030108000804 
Content-Type: text/html; charset=ISO-8859-15 
Content-Transfer-Encoding: 8bit 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
  <meta content="text/html;charset=ISO-8859-15" 
 http-equiv="Content-Type"> 
  <title></title> 
</head> 
<body bgcolor="#ffffff" text="#000000"> 
HT,<br> 
<br> 
When you call setElement with an element you constructed, it builds a 
model to reflects exactly what's in that element and it discards all 
the other information you might have set up that does not reflect 
what's in the element.
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.19291 seconds