[jgrapht-users] Seham, a post graduate student
Brought to you by:
barak_naveh,
perfecthash
From: seham m. <ss_...@ya...> - 2011-01-09 20:44:47
|
Dear Sir, I am now making a parser code for XSD documents. the results should be put in a tree data structure. Could you give me an implementation of a tree data structure such that it contains the following function: 1. every node can have more than one data item, a function to put that in a node. 1. every parent has any number of children (We build the tree from the parsing). 2. we can preorder and postorder the tree. 3. delete a node and get its parent[ to make a post order and delete the nodes one per one starting at the 1st node in the preorder and delete it and then get its parent] then put the nodes in an arraylist and the parents in another arraylist. 4. get siblings of the node. 5. get the ancestor path of any node 6. get the descendent path of any node 7. get the parent of any node This is what I want to do? may be there are other functions. CAN YOU HELP ME? (in Java code, please) Thanks \Seham \Seham --- On Sat, 1/8/11, Mansour Al Akeel <man...@gm...> wrote: > From: Mansour Al Akeel <man...@gm...> > Subject: Re: Fw: Re: Seham > To: "seham moawed" <ss_...@ya...> > Date: Saturday, January 8, 2011, 4:51 PM > Another thing I would like to ask you > about, what do you mean by "all > kind of schemas" ? And what do you mean all possible > strustures. > > On Sat Jan 08,2011 10:47 am, seham moawed wrote: > > > > Dear Eng.Mansour, > > look at the code I have done with XSOM, I > am sure it is not complete, I > > collect it from the codes appears in some > links for XSOM. Can you aid > > me to complete it to generalize it to all > kind of schemas? to all > > possible structures. > > package testxsd; > > import com.sun.xml.xsom.XSAttributeDecl; > > import com.sun.xml.xsom.XSAttributeUse; > > import java.io.File; > > import java.util.Iterator; > > import com.sun.xml.xsom.XSComplexType; > > import com.sun.xml.xsom.XSContentType; > > import com.sun.xml.xsom.XSElementDecl; > > import com.sun.xml.xsom.XSModelGroup; > > import com.sun.xml.xsom.XSParticle; > > import com.sun.xml.xsom.XSSchema; > > import com.sun.xml.xsom.XSSchemaSet; > > import com.sun.xml.xsom.XSTerm; > > import com.sun.xml.xsom.XSType; > > import > com.sun.xml.xsom.parser.XSOMParser; > > import java.util.Collection; > > /** > > * > > * @author soso > > */ > > public class TestXSD { > > public static void > parse(){ > > > try{ > > > XSOMParser parser = new XSOMParser(); > > > parser.parse(new File("C:/Documents and > > Settings/soso/Desktop/New > Folder/test.xsd")); > > > XSSchemaSet sset = parser.getResult(); > > > Iterator itr = sset.iterateSchema(); > > > while(itr.hasNext()) > > > { > > > XSSchema s = (XSSchema)itr.next(); > > > System.out.println("Target namespace: > > "+s.getTargetNamespace()); > > > Iterator jtr = s.iterateElementDecls(); > > > while( jtr.hasNext() ) { > > > XSElementDecl e = > (XSElementDecl)jtr.next(); > > > ProcessSchemaObject(e); > > > > > if( e.isAbstract() ) > > > > System.out.print(" (abstract)"); > > > > System.out.println(); > > > } > > > } > > > } > > > catch (Exception exp) { > > > exp.printStackTrace(System.out); > > } > > } > > public > static void ProcessSchemaObject(XSElementDecl e){ > > > XSType t = > e.getType(); > > > > if(t.isSimpleType()){ > > > System.out.println( > e.getName()); > > > System.out.println( > e.getType()); > > > > > } > > > > if(t.isComplexType()){ > > > System.out.println( > e.getName()); > > > XSComplexType > xsComplexType = (XSComplexType)t; > > > XSContentType > xsContentType = > > xsComplexType.getContentType(); > > > XSParticle particle = > xsContentType.asParticle(); > > > if(particle != null){ > > > XSTerm term = particle.getTerm(); > > > if(term.isModelGroup()){ > > > XSModelGroup xsModelGroup = term.asModelGroup(); > > > XSParticle[] particles = xsModelGroup.getChildren(); > > > for(XSParticle p : particles ){ > > > XSTerm pterm = p.getTerm(); > > > if(pterm.isElementDecl()){ //xs:element inside > complex > > type > > > //System.out.println(pterm); > > > final XSElementDecl x = > pterm.asElementDecl(); > > > ProcessSchemaObject(x); > > > > > } > > > } > > } > > } > > > > > > > Collection<? extends XSAttributeUse> > c = > > xsComplexType.getAttributeUses(); > > Iterator<? extends > XSAttributeUse> i = > > c.iterator();while(i.hasNext()){ > > > XSAttributeDecl attributeDecl = i.next().getDecl(); > > > System.out.println("name:"+attributeDecl.getName()); > > > System.out.println("type: "+attributeDecl.getType()); > > > > } > > > > > } > > > } > > > > > > > > /** > > * @param args > the command line arguments > > */ > > public static void > main(String[] args) { > > > > > parse(); > > } > > } > > the XSD is: > > <?xml version="1.0" > encoding="UTF-8"?> > > <schema xmlns = "http://www.w3.org/2001/XMLSchema" > > xmlns:target = "http://www.example.com/name" > > elementFormDefault = > "qualified"> > > <element > name="personaldata"> > > > <complexType> > > > <sequence> > > > <element name ="address" > > > > <complexType> > > > <choice> > > > <element name = "street" > type="string" /> > > > <element name = "country" > type="string" /> > > > </choice> > > > </complexType> > > > </element> > > > <element name ="fullname" > > > > <complexType> > > > <sequence> > > > <element name="first" > type="string"/> > > > <element name="middle" > type="string"/> > > > <element name="last" > type="string"/> > > > </sequence> > > > </complexType> > > > </element> > > > </sequence> > > <attribute > name="title" type ="string"/> > > > </complexType> > > </element> > > <element name="age" type > ="string"/> > > </schema> > > Could you do so??????????????? > > > > > Thanks > > > > > > \Seham > |