473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading XSD in Java

40 New Member
Hello,

I have an xsd file, and I would like to read its structure and display it as a JTree.
I know there are DOM and SAX parsers, but Im looking for something that would detect simple/complex types etc.
Is there any library able to do this? I know C# has XMLSchema, but I have to write in Java.

Cheers,

Charles
Aug 5 '08 #1
4 11547
Dököll
2,364 Recognized Expert Top Contributor
Java can do anything...

I thought to have seen somethings, give me a minute!
Aug 10 '08 #2
Dököll
2,364 Recognized Expert Top Contributor
Java can do anything...

I thought to have seen somethings, give me a minute!
Try this, I believe what you aksed for is this. Posting code instead, just in case link no longer works:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Author:    Fuhwei Lwo
  3.  */
  4. import java.io.FileOutputStream;
  5. import java.io.FileInputStream;
  6. import java.io.OutputStream;
  7.  
  8. import commonj.sdo.DataObject;
  9. import commonj.sdo.helper.DataFactory;
  10. import commonj.sdo.helper.XMLHelper;
  11. import commonj.sdo.helper.XSDHelper;
  12.  
  13. public class CreatePurchaseOrder {
  14.   private static final String PO_MODEL = "po.xsd";
  15.   private static final String PO_NAMESPACE = "http://www.example.com/PO";
  16.   private static final String PO_XML = "po.xml";
  17.  
  18.     private static void definePOTypes() throws Exception {
  19.      FileInputStream fis = new FileInputStream(PO_MODEL);
  20.      XSDHelper.INSTANCE.define(fis, null);
  21.      fis.close();
  22.     }
  23.  
  24.     public static void main(String[] args) throws Exception {
  25.      definePOTypes();
  26.  
  27.      DataObject purchaseOrder = 
  28.        DataFactory.INSTANCE.create(PO_NAMESPACE, "PurchaseOrderType");
  29.  
  30.      purchaseOrder.setString("orderDate", "1999-10-20");
  31.  
  32.      DataObject shipTo = purchaseOrder.createDataObject("shipTo");
  33.      shipTo.set("country", "US");
  34.      shipTo.set("name", "Alice Smith");
  35.      shipTo.set("street", "123 Maple Street");
  36.      shipTo.set("city", "Mill Valley");
  37.      shipTo.set("state", "CA");
  38.      shipTo.setString("zip", "90952");
  39.      DataObject billTo = purchaseOrder.createDataObject("billTo");
  40.      billTo.set("country", "US");
  41.      billTo.set("name", "Robert Smith");
  42.      billTo.set("street", "8 Oak Avenue");
  43.      billTo.set("city", "Mill Valley");
  44.      billTo.set("state", "PA");
  45.      billTo.setString("zip", "95819");
  46.      purchaseOrder.set("comment", "Hurry, my lawn is going wild!");
  47.  
  48.      DataObject items = purchaseOrder.createDataObject("items");
  49.  
  50.      DataObject item1 = items.createDataObject("item");
  51.      item1.set("partNum", "872-AA");
  52.      item1.set("productName", "Lawnmower");
  53.      item1.setInt("quantity", 1);
  54.      item1.setString("USPrice", "148.95");
  55.      item1.set("comment", "Confirm this is electric");
  56.  
  57.      DataObject item2 = items.createDataObject("item");
  58.      item2.set("partNum", "926-AA");
  59.      item2.set("productName", "Baby Monitor");
  60.      iteim2.setInt("quantity", 1);
  61.      item2.setString("USPrice", "39.98");
  62.      item2.setString("shipDate", "1999-05-21");
  63.  
  64.      OutputStream stream = new FileOutputStream(PO_XML);
  65.      XMLHelper.INSTANCE.save(purchaseOrder, PO_NAMESPACE, "purchaseOrder", stream);
  66.     }
  67. }
  68.  
Not sure of the legality of this, have not tried it myself, but I trust IBM:-) Here is the link:

http://www.ibm.com/developerworks/xm...ema/index.html

In a bit!
Aug 10 '08 #3
saddist
40 New Member
Thanks a lot! This was really helpful ;)
Aug 10 '08 #4
Dököll
2,364 Recognized Expert Top Contributor
Thanks a lot! This was really helpful ;)
Excellent, have fun:-)
Aug 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5421
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java...
114
9691
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
133
8424
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
235
11500
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
6
5451
by: sbalko | last post by:
Hi, I am trying to read Java-floats (IEEE 754 encoding) stored in a binary file from C (gcc on linux/i386, more specifically). Unfortunately, C seems to expect floats to be stored somewhat...
1
9585
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
1102
by: gm04030276 | last post by:
i have to learn java for college and im trying to do a programming assignment at home. in class we use a class file called InOut which simplifys input and output but i can't get the compiler to see...
15
2770
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interfaceâ€. In a functional language, a function can be specified by its name and parameter specs....
5
14968
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
6
3142
by: sapsi | last post by:
Hello, I am using HadoopStreaming using a BinaryInputStream. What this basically does is send a stream of bytes ( the java type is : private byte bytes) to my python program. I have done a...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.