Embedding a dtd with jdom

Does anyone know how to embed a dtd into the xml using jdom? Thanks,

I confused myself a bit there; it's not possible in the latest release but if you fetch the latest src from CVS, you'll see that DocType and XMLOutputter has added internal subset support (but AFAIKS it's just a string; no objects)...

Similar Messages

  • Please, if you have ever used schemas with JDOM !!!!!!

    How can we validate a document which refers to a schema rather than a DTD with JDOM ?
    I tried to do that but an error occured, telling to me that my root element isn't declared.
    Can someone help me ?

    Hi,
    If you want more information, go to this web page :
    http://www.jdom.org/docs/faq.html
    There is an answer to your question.

  • Creating XML doc from DTD using jDOM

    Hi...
    I want to create empty XML Document from the DTD using JDOM or JAXP & then want to populate that xml document with the values from the database.
    The problem is :-
         How can we create an XML document by simply reading the DTD using JDOM or JAXP.?
    or
    first of all how am i going to parse the DTD from jDOM or JAXp & then how will i create the empty XML Document from it..?
    Please revert back soon... & thanx in advance for helping..
    regards
    Shoorya

    Yes i've also got teh same problem this day...
    Can somone help us ?
    Thanks
    Math

  • 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);
    }

  • 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 .

  • Why are colors of embedded videos opened with acrobat different to original files?

    Hello,
    I generated a videoclip in Premiere CC in different formates ( mp4, mov; flv.... ) and embedded it in an Indesign document. From there I generated an interactive PDF. Opening the file in Acrobat, the colors of the video are different as in a videoplayer like quicktime. Opening the pdf in a browser like safari, the colors are correct. Alternative I embedded the video with acobat pro but the result was the same like before. What is the reason for this problem? Do I have to mange some special colorsetting in the video or are there some presettings to be done in Acrobat?

    If you open System Preferences / Displays / Color can
    you change the color profile to others in the list?
    Or, do you get a "beep" and no change?
    I can change the color profile.

  • 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

  • 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!

  • Transformation with JDOM (off-topic)

    Hi All,
    I am wondering if anyone could advice me on how to carry out transformation in a JDOM enviornment. I am familiar with querrying data using XPath with JDOM.
    Any tutorial or online reference material would be very much appreciated.
    I am running Netbeans 6.1, J2EE 5 Glassfish on Windows XP platform.
    Many thanks,
    Jack

    It contains the [org.jdom.transform|http://www.jdom.org/docs/apidocs/org/jdom/transform/package-summary.html] package with classes to do basic transformation. As the documentation says:
    Classes to help with transformations, based on the JAXP TrAX classes. JDOMTransformer supports simple transformations with one line of code. Advanced features are available with the JDOMSource and JDOMResult classes that interface with TrAX.

  • 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)

  • 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)

  • May LV for Linux run in embeded linux system with ARM9 ?

    Hello All,
    May LV for Linux run in embeded linux system with ARM9 ?
    Tks and best regards!
     Bright

    No, it will only run on Intel compatible processors.
    You'll need LV Microprocessor SDK for that (AKA LVEmbedded). But you'll lose
    the MMI. And you need to build toolchains yourself (although there is a
    cygwin example shipped, and converting it to any gcc toolchain is not that
    difficult).
    There is a special LV MSDK for ARM processors, but not for all of them.
    Regards,
    Wiebe.

  • Validating DTD with sequence embedded into choice

    Hey there!
    I have a validation problem. My XML file is coming with a DTD specifying that the element choice has the following structure (look at target and resource - I want both of them or one of them only, and that's my solution):
    <!ELEMENT choice ((question,target,answer,resource?,description?,number_of_questions?,query?)|
    (question,target?,answer,resource,description?,number_of_questions?,query?))>According to me, this is a correct element declaration.
    My XML document contains an element (amongst other):
    <choice name="Personnes celebres">
        <question> Qui est la personne representee sur la photo</question>
        <answer> name </answer>
        <resource> picture </resource>
        <number_of_questions> 50 </number_of_questions>
    </choice> According to me, it is valid according to the DTD, though when parsing, here is the code :
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    builder.setErrorHandler((ErrorHandler) new SimpleErrorHandler());
    Document localDocument = builder.parse(file);   // <-- HERE I get this error:
    org.xml.sax.SAXParseException: Element "choice" does not allow "answer" here.
            at org.apache.crimson.parser.Parser2.error(Parser2.java:3086)
            at org.apache.crimson.parser.ValidatingParser$ChildrenValidator.consume(ValidatingParser.java:349)
            at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1311)
            at org.apache.crimson.parser.Parser2.content(Parser2.java:1766)
            at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1494)
            at org.apache.crimson.parser.Parser2.content(Parser2.java:1766)
            at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1494)
            at org.apache.crimson.parser.Parser2.content(Parser2.java:1766)
            at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1494)
            at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
            at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
            at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
            at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
            at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:191)
            at quiz.server.QuizStructure.isValid(QuizStructure.java:85)
            at quiz.XMLFileFilter.accept(XMLFileFilter.java:35)
            at javax.swing.JFileChooser.accept(Unknown Source)
            at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(Unknown Source) If the element "target" is present (and either or not the element "resource"), then everything works fine.
    Can anybody help?
    Thanks in advance.
    Nick

    still no idea?
    nick

  • How to parse XML document with default namespace with JDOM XPath

    Hi All,
    I am having difficulty parsing using Saxon and TagSoup parser on a namespace html document. The relevant content of this document are as follows:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <div id="container">
            <div id="content">
                <table class="sresults">
                    <tr>
                        <td>
                            <a href="http://www.abc.com/areas" title="Hollywood, CA">hollywood</a>
                        </td>
                        <td>
                            <a href="http://www.abc.com/areas" title="San Jose, CA">san jose</a>
                        </td>
                        <td>
                            <a href="http://www.abc.com/areas" title="San Francisco, CA">san francisco</a>
                        </td>
                        <td>
                            <a href="http://www.abc.com/areas" title="San Diego, CA">San diego</a>
                        </td>
                  </tr>
    </body>
    </html>
    Below is the relevant code snippets illustrates how I have attempted to retrieve the contents (value of  <a>):
                 import java.util.*;
                 import org.jdom.*;
                 import org.jdom.xpath.*;
                 import org.saxpath.*;
                 import org.ccil.cowan.tagsoup.Parser;
    ( 1 )       frInHtml = new FileReader("C:\\Tmp\\ABC.html");
    ( 2 )       brInHtml = new BufferedReader(frInHtml);
    ( 3 ) //    SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
    ( 4 )       SAXBuilder saxBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser");
    ( 5 )       org.jdom.Document jdomDocument = saxbuilder.build(brInHtml);
    ( 6 )       XPath xpath =  XPath.newInstance("/ns:html/ns:body/ns:div[@id='container']/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a");
    ( 7 )       xpath.addNamespace("ns", "http://www.w3.org/1999/xhtml");
    ( 8 )       java.util.List list = (java.util.List) (xpath.selectNodes(jdomDocument));
    ( 9 )       Iterator iterator = list.iterator();
    ( 10 )     while (iterator.hasNext())
    ( 11 )     {
    ( 12 )            Object object = iterator.next();
    ( 13 ) //         if (object instanceof Element)
    ( 14 ) //               System.out.println(((Element)object).getTextNormalize());
    ( 15 )             if (object instanceof Content)
    ( 16 )                   System.out.println(((Content)object).getValue());
    ….This program would work on the same document without the default namespace, hence, it would not be necessary to include “ns” prefix along in the XPath statements (line 6-7) either. Moreover, I was using “org.apache.xerces.parsers.SAXParser” to have successfully retrieve content of <a> from the same document without default namespace in the past.
    I would like to achieve the following objectives if possible:
    ( i ) Exclude DTD and namespace in order to simplifying the parsing process. How this could be done?
    ( ii ) If this is not possible, how to include it in XPath statements (line 6-7) so that the value of <a> is picked up correctly?
    ( iii ) Would changing from “org.apache.xerces.parsers.SAXParser” to “org.ccil.cowan.tagsoup.Parser” make any difference as far as using XPath is concerned?
    ( iv ) Failing to exlude DTD, how to change the lookup of a PUBLIC DTD to a local SYSTEM one and include a local DTD for reference?
    I am running JDK 1.6.0_06, Netbeans 6.1, JDOM 1.1, Saxon6-5-5, Tagsoup 1.2 on Windows XP platform.
    Any assistance would be appreciated.
    Thanks in advance,
    Jack

    Here's an example of using a custom EntityResolver with the standard DocumentBuilder provided by the JDK. The code may or may not be similar for the parsers that you're using.
    import java.io.IOException;
    import java.io.StringReader;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.xml.sax.EntityResolver;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    public class ParseExamples
        private final static String COMMON_XML
            = "<music>"
            +     "<artist name=\"Anderson, Laurie\">"
            +         "<album>Big Science</album>"
            +         "<album>Strange Angels</album>"
            +     "</artist>"
            +     "<artist name=\"Fine Young Cannibals\">"
            +         "<album>The Raw & The Cooked</album>"
            +     "</artist>"
            + "</music>";
        private final static String COMMON_DTD
            = "<!ELEMENT music (artist*)>"
            + "<!ELEMENT artist (album+)>"
            + "<!ELEMENT album (#PCDATA)>"
            + "<!ATTLIST artist name CDATA #REQUIRED>";
        public static void main(String[] argv)
        throws Exception
            // this version uses just a SYSTEM identifier - note that it gets turned
            // into a file: URL
            String xml = "<!DOCTYPE music SYSTEM \"bar\">"
                       + COMMON_XML;
            // this version uses both PUBLIC and SYSTEM identifiers; the SYSTEM ID
            // gets munged, the PUBLIC ID doesn't
    //        String xml = "<!DOCTYPE music PUBLIC \"foo\" \"bar\">"
    //                   + COMMON_XML;
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setValidating(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.setEntityResolver(new EntityResolver()
                public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException
                    System.out.println("publicId = " + publicId);
                    System.out.println("systemId = " + systemId);
                    return new InputSource(new StringReader(COMMON_DTD));
            Document dom = db.parse(new InputSource(new StringReader(xml)));
            System.out.println("root element name = " + dom.getDocumentElement().getNodeName());
    }

Maybe you are looking for

  • Misleading error messages in Apex

    Hello all, I am looking at default values. I simply want to go to the database, call a functin and set the value using PL/SQL Function Body. Here is what happens: Check in SQL*Plus first ... blast:Blast-Bld@ORCL> delete blast_log; 6 rows deleted. bla

  • How I can include several sequences in one sequence file?

    I am new for teststand and forgive me if my question seems silly. How I can include several sequences in one sequence file? I would like to use " call sequence" in current file. thanks a lot for your kind help

  • Validation I/P Enabled field in the ALV grid

    Hi all, Which method is used for validating a value entered in a reprot output field of an ALV Grid OO report. can some one please throw some light on this. with a few example programs where it has been implemented. Regrds

  • Job Opening at Moog Bangalore, India

    Hello Friends, Moog Aircraft Group, Bangalore is looking for LabVIEW and TestStand Engineers with 2 to 5 years of experience in test automation field. Please find the job description as mentioned below. If interested, please send the resumes to urska

  • Working with badge.swf and air.swf (browser api)

    I basically want to install and run my app through the browser so ive been testing but can't manage to figure out how the air.swf api works. i am stuck at loading air.swf. the page below has a tutorial but a downloadable sample code would be perfect,