473,383 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Reading XSD in Java

40
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 11544
Dököll
2,364 Expert 2GB
Java can do anything...

I thought to have seen somethings, give me a minute!
Aug 10 '08 #2
Dököll
2,364 Expert 2GB
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
Thanks a lot! This was really helpful ;)
Aug 10 '08 #4
Dököll
2,364 Expert 2GB
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
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
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
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
235
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.