Manipulating XML with JDOM (IllegalAddException)

How can I add an element that already have an existing parent to another element that should be its new parent?
Currently I am getting an org.jdom.IllegalAddException because adding an element that have an parent to an new created element.
let say:
Element rootElem = doc.getRootElement();
Element firstChild = rootElem.getChild("servlet");
Element myNewElem = new Element("myelem");
myNewElem.addContent(firstChild );The code causes an org.jdom.IllegalAddException because firstChild have already an parent.
Is there a way to solve this.
Thanks a lot in advance:
Nermin B.

OK. I've found the nswer:
Element rootElem = doc.getRootElement();
Element firstChild = rootElem.getChild("servlet");
firstChild.detach();
Element myNewElem = new Element("myelem");
myNewElem.addContent(firstChild );I have overseen detach() method.]

Similar Messages

  • Updating xml with jdom

    I create a blank xml file when my user selects new:
    and I create a list of the elements
    <?xml version="1.0" encoding="UTF-8"?>
    <Root>
       <START/>
       <END/>
    </Root>User creates a new element, i insert the new element between start and end. It's there in the list, I confirmed that, but when I try to setContent on the root element(Root), I end with nothing in my xml file and my system print out.
    My xml file should lke tis afterwards:
    <?xml version="1.0" encoding="UTF-8"?>
    <Root>
       <START/>
       <element_one/>
       <END/>
    </Root>
            Element root = doc.getRootElement();
            /* create a new element */
            Element element = createNewElement();// returns new element
            elements.add((elements.size()-1),element);
            System.out.println(elements);// prints out "[start] [element_one] [end]"
            root.setContent(elements);
            System.out.println("after "+root.getContent());// prints out []So why is my content coming up blank?
    Thanks

    Try cloning the element and adding that to the root.

  • XML validation with JDOM / JAXP

    Hello,
    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    I did a first attempt but not sure I have understood all what I am doing :(
    First I have create a parser usinf org.jdom.*
    SAXBuilder parser = new SAXBuilderThen I built my document:
    Document doc = parser.build(myFile)These 2 steps are ok. But it does not do validation.
    I saw in the JDOM documentation that I can set a validation flag to true. I did it. First problem, I got the following error from JDOMException: Document is invalid: no grammar found.
    Is there a way to specify to the parser where to find the xsd file?
    As I did not find answer to this question by myself, I tried implementing the Schema class from JAXP:
    SAXBuilder parser = new SAXBuilder;
    Document doc = parser.build(myFile);
    Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile);
    ValidatorHandler vh = schema.newValidatorHandler();
    SAXOutputter so = new SAXOutputter(vh);
    so.output(doc);It does the validation against the schema file specified but I am not really sure about what I am doing here. The last 2 commands are not clear to me :(
    Then in my schema file, I have elements that have default value. I expected the following behavior: if the element is not in the xml file then the default will be used by the parser (and added in the tree). But it seems, it's not the case.
    Any help/explanation will be really appreciated.

    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    If only schema validation is required use the validation API in JDK 5.0.
    http://www-128.ibm.com/developerworks/xml/library/x-javaxmlvalidapi.html
    http://java.sun.com/developer/technicalArticles/xml/validationxpath/
    For validation with JDOM, the following validation application explains the procedure:import org.jdom.input.SAXBuilder;
    import org.xml.sax.SAXException;import org.jdom.*;
    import java.io.*;
    public class JDOMValidator{
    public void validateSchema(String SchemaUrl, String XmlDocumentUrl){
               try{
    SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser",true);<br/>saxBuilder.setValidation(true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
    saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",SchemaUrl);
    Validator handler=new Validator();
    saxBuilder.setErrorHandler(handler);
    saxBuilder.build(XmlDocumentUrl);
    if(handler.validationError==true)
    System.out.println("XML Document has Error:"+handler.validationError+""+
    handler.saxParseException.getMessage());      
    else           
          System.out.println("XML Document is valid");
              }catch(JDOMException jde){
                }catch(IOException ioe){
    private class Validator extends DefaultHandler{     
         public boolean  validationError = false; 
         public SAXParseException saxParseException=null;    
      public void error(SAXParseException exception) throws SAXException{        
         validationError =true;
         saxParseException=exception; 
      public void fatalError(SAXParseException exception) throws SAXException  {
    validationError = true;     
    saxParseException=exception;
      public void warning(SAXParseException exception) throws SAXException       {
    public static void main(String[] argv)   {
       String SchemaUrl=argv[0];StringXmlDocumentUrl=argv[1];
       JDOMValidator validator=new JDOMValidator();
       validator.validateSchema(SchemaUrl,XmlDocumentUrl);
    }

  • Modifying XML files with JDOM

    Hi:
    I've been trying to get up to speed with JDOM, and while it seems pretty intuitive, I've been having a problem w/ modifying XML documents.
    Namely, once I get a Document object from a (skeleton) XML file, do changes made to the Document object through, say, addContent() propagate to the original file? My gut feeling is no, although this was certainly what I had expected initially.
    Here's a code fragment of what I had tried to do to populate a barebones XML file:
                   Document doc = builder.build(output);
              // add 100 elements, all the same
              for (int count = 0; count < 100; count++)
                   Element curr = new Element("book");
                   // create child nodes for book
                   Element title = new Element("title");
                   title.addContent("Book " + (count + 1));
                   Element author = new Element("author");
                   author.addContent("Author " + (count + 1));
                   Element price = new Element("price");
                   price.addContent("Price " + (count + 1));
                   curr.addContent(title);
                   curr.addContent(author);
                   curr.addContent(price);
                   doc.getRootElement().addContent( curr );
              }

    Mikael,
    This sounds like one of the many quirks (perhaps bugs) related to how FrameMaker handles non-FM files in books. The current book model doesn't play well with XML files as chapters and this seems like yet another problem. Apparently, if an xref does not target another .fm file in the book, Frame assumes that the target file is not in the book and therefore will not be in the book PDF.
    There have been discussions here about this in the past. The solution that I use is to run an API client before publishing that converts all XML files to .fm files, and redirect all xrefs appropriately. Then, book features work as expected and PDFs come out as normal. This is not feasible, however, without the automation from the API client.
    There may be some who would say that the best approach is to use XML and books the way that the designers did account for... that is, the whole book becomes an XML document with entity references to the separate chapters. In my work, though, this model was not appropriate... rather, I needed a binary FM book to act like a book, except with XML files as chapters. So, I think I understand your situation.
    Is API programming or FrameScript an option for you? I think it may be the only way to get what you are looking for.
    Russ

  • How to merge two XML's with JDOM?

    How to merge two xmls's using jdom? like:
    is there a way to add the complete content one xml into the parent node of another xml?
    //in.xml
    <?xml version="1.0"?>
    <people>
    <person>
      <name>ABC</name>
      <email>[email protected]</email>
    </person>
    </people>
    //out.xml
    <?xml version="1.0"?>
    <address>
    <city> abccounty</city>
    <state> abcstate</state>
    </address>
    Merged XML:
    <?xml version="1.0"?>
    <people>
    <person>
      <name>xyz</name>
      <email>[email protected]</email>
    </person>
    <address>
    <city> abccounty</city>
    <state> abcstate</state>
    </address>
    </people>
    import java.util.List;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.Format;
    import org.jdom.output.XMLOutputter;
    public class MergeXMLS {
         public static void main(String[] args) {
              try{
                  SAXBuilder builder = new SAXBuilder();
                  Document books = builder.build("D:/in.xml");
                  Document onebook = builder.build("D:/out.xml");
                  Element root = books.getRootElement();
                  List rows = root.getChildren();
                  for (int i = 0; i < rows.size(); i++) {
                      Element row = (Element) rows.get(i);
                      onebook.getRootElement().addContent(row.detach());
                      System.out.println(row.getName());
                  new XMLOutputter(Format.getPrettyFormat()).output(onebook, System.out);
              }catch(Exception e){
                   e.printStackTrace();
    }

    The above code only add's the first node.
    I changed the code little differently to
                  SAXBuilder builder = new SAXBuilder();
                  Document books = builder.build("D:/in.xml");
                  Document onebook = builder.build("D:/out.xml");
                 //trying to add second xml into the first
                  books.getRootElement().addContent(onebook.getRootElement().getContent()); 
                  new XMLOutputter(Format.getPrettyFormat()).output(books, System.out);
    here is the exception from the above code:
    org.jdom.IllegalAddException: The Content already has an existing parent "address"
         at org.jdom.ContentList.add(ContentList.java:218)
         at org.jdom.ContentList.add(ContentList.java:140)

  • How To read an XML file with JDom

    I have read through some tutorials after installing JDom on how to read an existing XML file and I was confused by all of them. I simply want to open an XML file and read one of the node's content. Such as <username>john doe</username> this way I can compare values with what the user has entered as their username. I am not sure were to start and I was hoping someone could help me out.
    I know that this seems like an insecure way to store login information but after I master opening and writing XML files with JDom I am going to use AES to encrypt the XML files.

    Here is a test program for JDom and XPath use considering your XML file is named "test.xml" :import org.jdom.input.*;
    import org.jdom.xpath.*;
    public class JDomXPath {
    public static void main(String[] args) {
      SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
      try {
       org.jdom.Document jdomDocument = saxBuilder.build("test.xml");
       org.jdom.Element usernameNode = (org.jdom.Element)XPath.selectSingleNode(jdomDocument, "//username");
       System.out.print(usernameNode.getText());
      } catch (Exception e) {
       e.printStackTrace();
    }(tested with Eclipse)

  • Problem with JDOM and schemas

    I'm trying to parse (and validate) an XML document with JDOM.
    My root element is declared in the schaema whixh is asociated to the document.
    But during parsing, an exception saying that my root element is not declared is thrown.
    Can someone axplain to me what can happen ?
    Thank's

    What's this element ?
    My schema is indicated by the xsi:schemeLocation attribute of my root-element .

  • Adding CDATA To every element in xml _ JDOM

    Hi,
    I need to parse xml using JDOM and add
    CDATA to every element.
    Could anyone help me in that ?
    When I append CDATA using org.jdom.Element.setText("<!CDATA"+Mystring +"]]>" );
    CDATA has been treated like text but not as an instruction .

    Question: Please see the code below.............
    I am copying a text which is in Hindi(DBWT-yogesh font) in JTextPane. When I am trying to retrieve hindi text from JTextpane using getText() I am obtaining hashampersand123,hashampersand156(hashsymbol,ampsymbol,123;like that ) some thing like this.
    If I dont set contentType to text/html and use getText()
    I obtain some junk characters. If I copy those junk characters in xml
    and view the xml with notepad and change the font to DBWT-yogesh
    I can see hindi text.
    I need to setContentType to html because I want to display text
    as bold or italic depending on html tags in content. when I use getText() I obtain some thing like this. If I store these characters even after changing font to DBWT-Yogesh I am not able to see hindi text.
    I want to convert (hashsymbol,ampsymbol,123;like that ) to junk characters so that when I change font using notepad I must be able to see hindi text.
    Please provide help............................. your earlier answer took me in the right direction.
    package swin;
    import java.awt.Font;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowListener;
    import javax.swing.JFrame;
    import javax.swing.JTextPane;
    public class TextPaneProblem extends JFrame implements WindowListener{
    JTextPane jtp=null;
    public TextPaneProblem() {
    jtp=new JTextPane();
    jtp.setContentType("text/html");
    jtp.setFont(new Font("DWB-Yogesh",Font.PLAIN,24));
    getContentPane().add(jtp);
    setVisible(true);
    public static void main(String[] args) {
    TextPaneProblem TPP=new TextPaneProblem();
    TPP.addWindowListener(TPP);
    public void windowOpened(WindowEvent e) {
    public void windowClosing(WindowEvent e) {
    }

  • Urgent :::::.i WISH TO DO THIS WITH JDOM and JAVA .

    file A.XML
    <XML>
    <TP>
    <FF>
    </FF>
    </TP>
    </XML>
    file B.XML
    <XML>
    <TP>
    <GG>
    </GG>
    </TP>
    </XML>
    I WANT TO PASTE node GG in b.xml to a.xml like this
    <XML>
    <TP>
    <FF>
    <GG>
    </GG>
    </FF>
    </TP>
    </XML>
    i WISH TO DO THIS WITH JDOM and JAVA .
    Please let me know how to do this ....
    i dont want to use XSL OR XSLT ...
    i am free for discussions...pls help me
    ciao

    You can try these steps in case of issues with web pages:
    Reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Hold down the Shift key and left-click the Reload button
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (Mac)
    Clear the cache and cookies only from websites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Better with JDom or not?

    Hello, I have one function to create a XML structure without use JDom. I read my strings and I create a Xml. It's difficult but I have already done. But my question is if it's easyer use JDom and create a new function.
    Here my String
    Name
    Name.Surname
    Name.Surname,Second
    Name.Surname.First
    Name2
    Name.Surname
    Name2.Surname.Folder
    Name2.Structure
    I want this Xml:
    <Cuenta id="xx" label="xx1">
    <node label="Borrador"></node>
    <node label="Name">
        <node label="Surname">
                  <node label="Second"</node>
                  <node label="First"></node>
        </node>
    </node>
    <node label="Name2">
        <node label="Surname">
                  <node label="Folder"</node>
        </node>
        <node label="Structure"></node>
    </node>
    </Cuenta>Exist any easy way to do that? Or it's better if I continue with my method(it's difficult and if I have to change something I have to change a lot of things. I want one function to create that dinamicaly, not always is the same list. My function do dinamicaly but it's not very clear for other people.
    Thanks!

    Now I'm creating manually and then I use JDom to transform to Xml and edit if I have to change something. You said that you would use JDom to create. To say the truth I'm a newbie with JDom, and I know how can create a very simple document, but not how can create this Xml starting with my list. I have to use split to separate the folders and ..... but I don't know how can create the Xml.
    Now I have my old solution but if you see easy that this function using JDom, can you say me how can I do or some      
    recommendations. Or if you show veryvery easy you can put the code, just kidding, hahaha (don't worry it's enough with some recomendations).
    This is my actual code, has you can see it's a little complicate, I think that with JDom the code will be much more understandable.
    public static String crearStringXML(lista) throws MessagingException, IOException
                    java.util.Collections.sort(lista);//order the lsit
                   String textOut="<Cuenta id=\"cuenta"+id+"\" label=\""+user+"\">";
                   String[] oldPath = new String[0];
                   String[] newPath=null;
                   for(String path : lista) {
                        newPath = path.split("\\.");//dvide the folders
                      int matchLen = 0;
                      // To calculate how many are the same
                      while(matchLen < oldPath.length && matchLen < newPath.length && oldPath[matchLen].equals(newPath[matchLen]))
                              matchLen++;
                      for(int i = matchLen; i < oldPath.length; i++) {
                           textOut += "</node>";
                      for(int i = matchLen; i < newPath.length; i++){
                         textOut += "<node label=\"";
                         textOut += newPath[i]+"\">";
                     oldPath = newPath;
                   for(int i =0;i< newPath.length;i++)
                        textOut +="</node>";
                   textOut += "</Cuenta>";
                   return textOut;
              }Thanks!

  • How to edit xml using jdom

    hi
    how to read and edit xml file using jdom, i tried using
    javax.xml.transform.*; // JAXP
    javax.xml.transform.dom.DOMSource; //
    i can read xml file . but iam not able to edit the xml file.
    how to achive this

    1. Select nodes to be modified with the JDom XPath class selectSingleNode and selectNodes methods.
    SAXBuilder saxBuilder=new SAXBuilder("org.apache.xerces.parsers.SAXParser");
    org.jdom.Document jdomDocument=saxBuilder.build(new File("c:/input.xml"));
    org.jdom.Element node= (org.jdom.Element)(XPath.selectSingleNode(jdomDocument,"/root/node"));
    2. Modify the node values with the Element class setter methods.
    3. Output document with the XMLOutputer class.

  • Can i do this with jdom

    Hi
    i need to open an xml file, then modify it and then put its content into a string without modifying the physical file.
    Can i do this with jdom?
    I know that i can use some methods to build an object from a physical file, and also modify it, but then can i get the full content and put it into a string?
    Thanks

    Yep, you can do that with JDOM. U can use org.jdom.output.XMLOutputter to put the modified contents into a String. (Using a StringWriter)

  • Unable to transform XML with XSL in java code

    Hi,
    Could somebody please tell me what's wrong with my code, why it isn't transform the XML with XSL to the output that I want. If I use the command line to transform the XML, it output perfectly:
    java org.apache.xalan.xslt.Process -in marc.xml -xsl MARC21slim2MODS.xsl -out out.xml
    Here is the code of my program to transform the XML with XSL, I am using xalan-j_2_2-bin:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    import javax.xml.transform.dom.*;
    import java.math.BigInteger;
    String xslDoc = "MODS.xsl";
    String xmlResult = "out.xml";
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    dfactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
    Document xmlDoc = docBuilder.newDocument();
    Element root = xmlDoc.createElement("collection");
    root.setAttribute("xmlns", "http://www.loc.gov/MARC21/slim");
    xmlDoc.appendChild(root);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(new StreamSource(xslDoc));
    FileWriter fw = new FileWriter(new File(xmlResult));
    StreamResult output = new StreamResult(fw);
    transformer.transform(new DOMSource(xmlDoc), output);
    fw.flush();
    fw.close();
    ========================
    marc.xml -- source XML file
    ========================
    <?xml version="1.0" encoding="UTF-8"?>
    <collection xmlns="http://www.loc.gov/MARC21/slim"><record><leader>01488cam 2200337 a 4500</leader><controlfield tag="001">2502929</controlfield><controlfield tag="005">19930521155141.9</controlfield><controlfield tag="008">920219s1993 caua j 000 0 eng </controlfield><datafield ind1=" " ind2=" " tag="035"><subfield code="9">(DLC) 92005291</subfield></datafield><datafield ind1=" " ind2=" " tag="906"><subfield code="a">7</subfield><subfield code="b">cbc</subfield><subfield code="c">orignew</subfield><subfield code="d">1</subfield><subfield code="e">ocip</subfield><subfield code="f">19</subfield><subfield code="g">y-gencatlg</subfield></datafield>
    </record></collection>
    ========================
    out.xml -- result using command line
    ========================
    <?xml version="1.0" encoding="UTF-8"?>
    <collection xmlns="http://www.loc.gov/mods/" xmlns:xlink="http://www.w3.org/TR/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/ http://www.loc.gov/standards/marcxml/schema/mods.xsd">
    <mods>
    <titleInfo>
    <title>Arithmetic</title>
    </titleInfo>
    <name type="personal">
    <namePart>Sandburg, Carl</namePart>
    <namePart type="date">1878-1967</namePart>
    <role>creator</role>
    </name>
    </mods>
    </collection>
    ========================
    out.xml -- result using my java program
    ========================
    <?xml version="1.0" encoding="UTF-8"?>
    <collection xmlns="http://www.loc.gov/mods/" xmlns:xlink="http://www.w3.org/TR/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/ http://www.loc.gov/standards/marcxml/schema/mods.xsd">01488cam 2200337 a 4500250292919930521155141.9920219s1993 caua j 000 0 eng (DLC) 920052917cbcorignew1ocip19y-gencatlgpc16 to br00 02-19-92; br02 to SCD 02-21-92; fd11 02-24-92 (PS3537.A618 A...); fa00 02-26-92; fa05 03-02-92; fm31 03-06-92; CIP ver. pv08 04-16-93; pv01 to CLT 04-20-93; lb10 05-21-93
    </collection>

    I am using the same XSL file. My Java program use the same XSL file I used in the command line.
    It is possible that my Java code is using a different parser, but I developed a seperate program to parse the XML using the same parser that my Java code is using. It output the result I expected. Here is the code for the program:
    import java.io.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    public class Convertor {
    public static void main(String[] args) throws Exception {
    String xslDoc = "MARC21slim2MODS.xsl";
    String xmlResult = "out.xml";
    String xmlDoc = marc.xml";
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(new StreamSource(xslDoc));
    StreamSource xmlSource = new StreamSource(xmlDoc);
    FileWriter fw = new FileWriter(new File(xmlResult));
    StreamResult output = new StreamResult(fw);
    transformer.transform(xmlSource, output);
    }

  • How to save as XML with some predefined extensions

    hi All,
    In my application a template has to be created which should contain field headers and their respective field types - example field header LEVEL and field type COMBO BOX. Purpose is - a table will be created based on the fields in the template. Now I want to save this template as XML file with some predefined extension (like .templ). Later in my application i will retreive the saved template and use it to create table.
    How can i save the file as XML with some predefined extension. We are using Swing to create template. Please help me with sample programs to solve this problem.
    awaiting for your mail
    Thank you
    Regards
    MKumar

    In an other post I found my solution thanks to "Peggy" :
    Save As… has returned with Mountain Lion. Hold down the Option/alt key while clicking on the File menu & there it is! It also has a default keyboard shortcut.
    Thank you Peggy

  • Persisting unexplained errors when parsing XML with schema validation

    Hi,
    I am trying to parse an XML file including XML schema validation. When I validate my .xml and .xsd in NetBeans 5.5 beta, I get not error. When I parse my XML in Java, I systematically get the following errors no matter what I try:
    i) Document root element "SQL_STATEMENT_LIST", must match DOCTYPE root "null".
    ii) Document is invalid: no grammar found.
    The code I use is the following:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    My XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- Defining the SQL_STATEMENT_LIST element -->
    <xs:element name="SQL_STATEMENT_LIST" type= "SQL_STATEMENT_ITEM"/>
    <xs:complexType name="SQL_STATEMENT_ITEM">
    <xs:sequence>
    <xs:element name="SQL_SCRIPT" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <!-- Defining simple type ApplicationType with 3 possible values -->
    <xs:simpleType name="ApplicationType">
    <xs:restriction base="xs:string">
    <xs:enumeration value="DawningStreams"/>
    <xs:enumeration value="BaseResilience"/>
    <xs:enumeration value="BackBone"/>
    </xs:restriction>
    </xs:simpleType>
    <!-- Defining the SQL_SCRIPT element -->
    <xs:element name="SQL_SCRIPT" type= "SQL_STATEMENT"/>
    <xs:complexType name="SQL_STATEMENT">
    <xs:sequence>
    <xs:element name="NAME" type="xs:string"/>
    <xs:element name="TYPE" type="xs:string"/>
    <xs:element name="APPLICATION" type="ApplicationType"/>
    <xs:element name="SCRIPT" type="xs:string"/>
    <!-- Making sure the following element can occurs any number of times -->
    <xs:element name="FOLLOWS" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    and my XML is:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Document : SQLStatements.xml
    Created on : 1 juillet 2006, 15:08
    Author : J�r�me Verstrynge
    Description:
    Purpose of the document follows.
    -->
    <SQL_STATEMENT_LIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.dawningstreams.com/XML-Schemas/SQLStatements.xsd">
    <SQL_SCRIPT>
    <NAME>CREATE_PEERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE PEERS (
    PEER_ID           VARCHAR(20) NOT NULL,
    PEER_KNOWN_AS      VARCHAR(30) DEFAULT ' ' ,
    PRIMARY KEY ( PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITIES_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITIES (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    COMMUNITY_KNOWN_AS VARCHAR(25) DEFAULT ' ',
    PRIMARY KEY ( COMMUNITY_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE CACHED TABLE COMMUNITY_MEMBERS (
    COMMUNITY_ID VARCHAR(20) NOT NULL,
    PEER_ID VARCHAR(20) NOT NULL,
    PRIMARY KEY ( COMMUNITY_ID, PEER_ID )
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_PEER_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE PEERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITIES_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITIES IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>DROP_COMMUNITY_MEMBERS_TABLE</NAME>
    <TYPE>DELETION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    DROP TABLE COMMUNITY_MEMBERS IF EXISTS
    </SCRIPT>
    </SQL_SCRIPT>
    <SQL_SCRIPT>
    <NAME>CREATE_COMMUNITY_MEMBERS_VIEW</NAME>
    <TYPE>CREATION</TYPE>
    <APPLICATION>DawningStreams</APPLICATION>
    <SCRIPT>
    CREATE VIEW COMMUNITY_MEMBERS_VW AS
    SELECT P.PEER_ID, P.PEER_KNOWN_AS, C.COMMUNITY_ID, C.COMMUNITY_KNOWN_AS
    FROM PEERS P, COMMUNITIES C, COMMUNITY_MEMBERS CM
    WHERE P.PEER_ID = CM.PEER_ID
    AND C.COMMUNITY_ID = CM.COMMUNITY_ID
    </SCRIPT>
    <FOLLOWS>CREATE_PEERS_TABLE</FOLLOWS>
    <FOLLOWS>CREATE_COMMUNITIES_TABLE</FOLLOWS>
    </SQL_SCRIPT>
    </SQL_STATEMENT_LIST>
    Any ideas? Thanks !!!
    J�r�me Verstrynge

    Hi,
    I found the solution in the following post:
    Validate xml with DOM - no grammar found
    Sep 17, 2003 10:58 AM
    The solution is to add a line of code when parsing:
    try {
    Document document;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File(PathToXml) );
    The errors are gone !!!
    J�r�me Verstrynge

Maybe you are looking for

  • Servlet Execution Problem

    I have installed Apache Tomcat/6.0.10. Can you please tell me what is the process for running servlet in it. There is no any problem in the compilation of servlet. Rakesh Kumar

  • I am using itouch for music can i also us my nano 3rd generation to uploat podcasts only from the same library?

    I have an ipod touch that i use for my music in itunes, my question is can i restore an older nano 3rd generation ipod and use it for podcasts only, from the same account that i use for the itouch...sorry if this doesnt make sence! I want to use two

  • Keyboard inaccurate after a sentance or two

    I have had a problem with my keyboard since 2 updates ago. Any typing app after 1-2 sentences the typing doesn't register. It will register a letter 2 spaces to the left. I am unable to type P, L, or M as they are on the right side of the keyboard. I

  • Upgrade hard drive for macbook pro

    I am planning on upgrading to a 300GB Hard drive on my 2.33GHz core 2 duo 15.4" macbook pro. Any recommendation?

  • Images or css images

    heyall, how is best to simply update your index.jsp file to and bring in some images to your web page? is it better practice to create new .jsp files for this? is there any rules to follow? Thanks