A Jdom problem !!

my program recieve String content = "<start>aaa</start>" from other application, and i wanna use Class SAXBuilder() to build a XML document base on that String
but SAXBuilder only take argruments of File and Stream
is any other way i can do it???????????????

RTFM. It says the direct known subclasses of Reader are these:BufferedReader, CharArrayReader, FilterReader, InputStreamReader, PipedReader, StringReaderWhich of them look like they might be able to read a String? Guessing is okay here because you can check your answer against the documentation.
Seriously, if you don't get in the habit of looking in the API documentation to see what is available you will find it very difficult to write Java programs.

Similar Messages

  • XSLT usage with JDOM problem

    When I try to do an XSL transformation on a JDOM tree
    using Oracle's xml classes from xmlparserv2.jar (includes
    the javax.xml.transform api) I get the following:
    java.lang.ClassCastException: org.jdom.transform.JDOMSource$DocumentReader
         at oracle.xml.jaxp.JXTransformer.transform(JXTransformer.java:201)
    The same code works with xalan/crimson as well as saxon/aelfred, anyone
    seen this and knows a solution? Code snippet:
    private Frame transform(Document in, URL stylesheet) {
         TransformerFactory f = TransformerFactory.newInstance();
         InputStream s = stylesheet.openStream();
         Transformer transformer = f.newTransformer(new StreamSource(s));
         JDOMResult out = new JDOMResult();
         out.setFactory(new FPLNodeFactory());
         transformer.transform(new JDOMSource(in), out);
         s.close();
         return (Frame)out.getDocument().getRootElement().detach();
    I was wondering if there is a problem with the Oracle's impelmentation or am I using it incorrectly.
    Thanks.
    Suhas.

    This forum is mostly reviewed by folks using the XML features in the database (which basically means version 9.2). This is an XDK question--I would post it to Technologies > XML > General.

  • XML, jdom problem

    Hello Java-People,
    I am having a problem with Java and XML using the jdom package (www.jdom.org).
    An exception
    (java.lang.NoClassDefFoundError: org/xml/sax/SAXNotRecognizedException
         at YAAFile.openXMLDataFile(YAAFile.java:161))
    is thrown.
    I use java 1.4.1_01 on MacOS X (10.2.6). My IDE is Project Builder.
    The following classes are involved:
    YAAObject: stores my data in bean style with setters and getters, only used to hold the data.
    YAAFile: holds the YAAObject instances in a vector and saves them in a xml file, opens xml file and returns the objects to other classes.
    A third class that holds the YAAFile class.
    1st test scenario:
    My class YAATest calls:
    YAAFile f1 = new YAAFile();
    f1.openXMLDataFile();
    YAAObject[] array = f1.returnYAAObjectArray();
    for (int i = 0; i < array.length; i++){
    array.outputData();
    This works fine. The outputData() method puts the content via System.out.println() on the console.
    2nd (application) scenario:
    My class YouAreAl calls:
    (above) YAAFile currentYAAFile;
    currentYAAFile = new YAAFile();
    currentYAAFile.openXMLDataFile();
    Does not work. I get the output:
    java.lang.NoClassDefFoundError: org/xml/sax/SAXNotRecognizedException
         at YAAFile.openXMLDataFile(YAAFile.java:161)
         at YouAreAl.<init>(YouAreAl.java:173)
         at YouAreAl.main(YouAreAl.java:260)
         at java.lang.reflect.Method.invoke(Native Method)
         at apple.launcher.LaunchRunner.run(LaunchRunner.java:88)
         at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
         at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)
    -[NSJavaVirtualMachine initWithClassPath:] cannot instantiate a Java virtual machine
    YouAreAl has exited with status 0.
    Both scenarios execute the following code at the openXMLDataFile() method:
    protected void openXMLDataFile(){
    builder = new SAXBuilder(); //here the exception is thrown!
    Document doc = null;
    try{
    doc = builder.build(DataFileName);
    catch (JDOMException e)
    System.err.println("JDOMException openXMLDataFile 1");
    System.err.println(e.getMessage());
    catch (IOException e)
    System.err.println("IOException openXMLDataFile 3");
    System.err.println(e.getMessage());
    ...and so on...
    The exception is thrown at line:
    builder = new SAXBuilder();
    As both scenarios execute the same piece of code I do not understand where the difference is.
    I have the jdom.jar in the Library/Java/Extensions directory.
    In my opinion builder wants to throw the SAXNotRecognizedException but can not find it. The point is why does it not word in the second scenario when everything is fine in the first one?
    If there is anyone out there having a deeper understanding of this matter, please give me a hint.
    Thanks in advance
    Tobias

    Hi people,
    I found the problem. I'll post it here in case anyone runs into the same kind of problem.
    The reason for the exception was not the source code but the built product.
    Scenario one built a .jar file and it worked just fine.
    Scenario two built an .app file and it threw an exception.
    When compiling scenario two on the console it ran fine as well. So thr problem seems to lie either in the packaging or the IDE. It looks as if you are not allowed to use extensions when packaging your class files as an .app
    So I'll stick with jar files for a while...
    Regards,
    Tobias

  • Parsing a XML file using Jdom-Problem.

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    }~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

    LOL
    This is what you get for working 12 hours straight....
    I changed:
    xmlObject["mydoc"]["modelglue"]["event-handlers"]["event-handler"][i].xmlAttrib utes["name"]<br>
    to:
    #mydoc["modelglue"]["event-handlers"]["event-handler"][i].xmlAttrib utes["name"]#<br>
    xmlObject is the name of my xml object in memory, and then you reference from the root of the xml doc down the chain.
    Sorry for the inconvenience,
    Rich

  • Parsing a XML using Jdom --- Problem pls help

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    }~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

    One suggestion to try:
    Change your code to the following
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    Namespace ns = Namespace.getNamespace(
      "http://schemas.xmlsoap.org/ws/2003/03/business-process/" );
    List list= root.getChildren("partnerLinks", ns );
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());The JavaDoc says for the one-arg getChildren()
    If this target element has no nested elements with the given name outside a namespace, an empty List is returned.
    Your elements have a namespace (the default one) so it should be worth a try.
    Dave Patterson

  • Jdom problem

    Hi all,
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element.Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("file location "));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println(list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println(list2.size());
    Iterator it2= list2.iterator();
    String[][] partnerLinkval = new String [2][list2.size()];
    int i=0,j=0;
    while(it2.hasNext())
    Element el2= (Element)it2.next();
    String ElementName = el2.getName();
    partnerLinkval[j]= ElementName;
    j++;
    String Attribute = el2.getAttributeValue("myRole");
    partnerLinkval[j]= Attribute;
    i++;
    j--;
    System.out.println("Saving in array "+el2.getName());
    System.out.println("Saving in array "+Attribute);
    System.out.println("array length"+partnerLinkval.length);
    for (int l=0;l<2;l++){
    for(int k=0;k<partnerLinkval.length;k++)
    System.out.println(partnerLinkval[l][k]);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file
    process
    tgt ns http://serena.com/buildserviceflow
    1
    2
    Saving in array partnerLink
    Saving in array BpelServiceFlowProvider
    Saving in array partnerLink
    Saving in array null
    array length2
    partnerLink
    BpelServiceFlowProvider
    partnerLink
    null
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    0

    Please re-post your code using the [code] tags - http://forum.java.sun.com/help.jspa?sec=formatting. Also, please say what it does not do that it should do (or what it does that it should not do)?

  • Intresting problem with JDOM and xmlns in root element.

    Hi all,
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element.Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
              <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
              <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
         </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("file location "));
         Element root = oDoc.getRootElement();
         System.out.println(root.getName());
         String tgtns= root.getAttributeValue("targetNamespace");
         System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
         Iterator it1= list.iterator();
         System.out.println(list.size());
         while(it1.hasNext()){
              Element partnerlinks = (Element)it1.next();
              List list2= partnerlinks.getChildren("partnerLink");
              System.out.println(list2.size());
              Iterator it2= list2.iterator();
              String[][] partnerLinkval = new String [2][list2.size()];
              int i=0,j=0;
              while(it2.hasNext())
                   Element el2= (Element)it2.next();
              String ElementName = el2.getName();
              partnerLinkval[i][j]= ElementName;
              j++;
              String Attribute = el2.getAttributeValue("myRole");
              partnerLinkval[i][j]= Attribute;
              i++;
              j--;
              System.out.println("Saving in array "+el2.getName());
              System.out.println("Saving in array "+Attribute);
              System.out.println("array length"+partnerLinkval.length);
              for (int l=0;l<2;l++){
              for(int k=0;k<partnerLinkval.length;k++)
                   System.out.println(partnerLinkval[l][k]);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file
    process
    tgt ns http://serena.com/buildserviceflow
    1
    2
    Saving in array partnerLink
    Saving in array BpelServiceFlowProvider
    Saving in array partnerLink
    Saving in array null
    array length2
    partnerLink
    BpelServiceFlowProvider
    partnerLink
    null
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    0

    Hi,
    I am also having the same problem using jdom, my code works fine when there is no xmlns attribute but when i put the xmlns attribute back in doesn't work.
    Did you manage to find a way to solve this problem?

  • Problem with JDOM and euro character

    Hi,
    I have an xml file including euro characters (�) and starting with :
    <?xml version="1.0" encoding="ISO-8859-15"?>
    as it should probably be.
    However, my problem is that (JDOM and) SAXBuilder doesn't recognize the euro characters and replace them by an unknown character '?'.
    What's wrong and how can I solve it?
    Thanks in advance.

    All right, this is a a part of my code:
    ....SAXBuilder builder = new SAXBuilder( true );
    //create the document
    //this doc contains this tag <RefVersion> data�data </RefVersion>
    Document doc = builder.build( "E:\\test.xml" );
    System.out.print( "before charAt = " + "�".charAt(0) + String.valueOf('\u20ac') );
    String str = "euro�euro";
    System.out.println( "euro�euro ->" + str.replace('\u20ac','O') );
    Element root = doc.getRootElement();
    //recup du noeud RefVersion
    Element version = root.getChild( "RefVersion" );
    str = version.getText();
    System.out.println( "nom= " + version.getName() + " data= " + str );
    System.out.println( "index de � ds euro�euro " + str.replace('\u20ac','O') );
    and the output is:
    before charAt = ��
    euro�euro ->euroOeuro
    nom= RefVersion data= data?data
    index de � ds euro�euro data?data
    So, obviously, it comes from JDOM.

  • Problems with JDOm XPath

    Hi all.
    I have a JDOM XML document and I use JDOMXPath to apply XPath expressions on the XML document.
    I have XPath expression for which JDOMXPath does not match any node:
    //*[not(count(descendant::a) < 4)]
    [not(descendant::node()[count(descendant::a)>3])]
    [not(descendant::text()[normalize-space(string())!='']
    [not(ancestor::a)])]
    XML parser such as Saxon, MSXML, etc. correctly match this XPath on the document and find the appropriate node-set, so the XPath expression is 100% right from the XPath syntax perspective.
    But in JDOM, it does not match.
    Could anybody tell me what is the problem?
    Thank you very much for help and sorry if this is the wrong place to ask this question - this is my first post here.
    Thanks again,
    Anna

    Sorry, forgot to tell something very important:
    the XML node-set that I am trying to match is as follows:
    <ul>
    <li>Accessibility</li>
    <li>Amaya</li>
    <li>ABC</li>
    <li>CC/PP</li>
    </ul>
    The interesting moment is, that if I change the node-set to look like this:
    <ul><li>Accessibility</li><li>Amaya</li><li>ABC</li><li><a href="Mobile/CCPP/"></a></li></ul>
    i.e. without any spaces, JDOMXPath will match for the above XPath.
    Is there any problem with spaces in JDOM/JDOMXPath?
    Thanks again
    Anna

  • Jdom and namspace problem.

    Hi, everyone
    I have some problem with jdom documet. When i put namespace on root element all child elemets gets empty namspace.
    Code
    Namespace ns = Namespace.getNamespace(XMLNS);
              Element e = new Element("root",ns);
              e.addContent(new Element("element"));
    result (validation by schema fails)
    <root xmlns="httpo://someuri.com">
    <element xmlns="">
    </element>
    </root>
    i need result
    <root xmlns="httpo://someuri.com">
    <element>
    </element>
    </root>

    Hi, again i have solwed my problem by myself, and i want to share information with you :).
    *Namespace ns = Namespace.getNamespace(XMLNS);*
    Element e = new Element("root",ns);
    e.addContent(new Element("element"));when creating new namespace lement don't forget create it with prefix.
    *Namespace ns = Namespace.getNamespace("ns", XMLNS);*
    Element e = new Element("root",ns);
    e.addContent(new Element("element"));

  • JDom package problem !!!

    Hi, Friends
    I have some problem while using JDom v1.0 from www.jdom.org
    since while i have seen all the examples on the net, they
    using org.jdom.*; package structure.
    but when i am using latest libs from v1.0 there is no package
    like org.jdom
    what should i do ??
    Since it giving me error while running below code :
    public class JdomEx1
        public static void main(String[] args)
            Element root = new Element("myRootElement");
            Document doc = new Document(root);
            root.setText("This is a root element");
            System.out.println(doc);
    D:\netBeans Projects\appDom1\src\mydom\JdomEx1.java:21: org.w3c.dom.Element is abstract; cannot be instantiated
            Element root = new Element("myRootElement");
    D:\netBeans Projects\appDom1\src\mydom\JdomEx1.java:22: org.w3c.dom.Document is abstract; cannot be instantiated
            Document doc = new Document(root);
    D:\netBeans Projects\appDom1\src\mydom\JdomEx1.java:23: cannot find symbol
    symbol  : method setText(java.lang.String)HELP

    georgemc wrote:
    Ghanshyam wrote:
    BIJ001 wrote:
    There is a hint to org.w3c.dom.Element in the error mesasge in your post and we are talking about jdom.
    I am a happy user of jdom without a problem. Correct classpath setting is your friend.===========================================
    Hi Friend,
    Thanks for that,
    I want to ask , then how to run the sample code ??
    consider me as new java newbie.
    and there is no issue for classpath, Netbeans 5 will do that.And you, in your infinite Java newbie wisdom, can be 100% sure that there is no classpath issue, despite blatant evidence to the contrary?? :-)
    It is a classpath issue, and since you're using an IDE, and no doubt making use of code completion, you've gone stampeding down the DOM route and got yourself stuck! Try writing a bit of code outside of NetBeans, and sort your classpath out========================================
    Hi friend,
    Thanks for suggestion, but still there is no solution
    Can u tell me to run code in IDE ?
    i have added following libs to NetBeans Library area.
    1) ant.jar
    2) jaxen-jdom.jar
    3) xalan.jar
    4) saxpath.jar
    5) xerces.jar
    6) xml-apis.jar
    My Whole project is in Netbeans and you told me to write XML
    code outside IDE, don't u think it is strange !!!
    then what purpose of IDE ???
    Kindly provide me solution if any classpath issue....
    Thanks..

  • Problems with JDom

    In my Jdom program I got the following errors during compilation. It could compile on one machine,
    but it did not on another,even though I made sure the machines are set up properly:
    package com.sun.java.util.collections does not exist
    import com.sun.java.util.collections.*;
    ^
    file com\sun\java\util\collections\List.class not found
    outputter.output(jdomDocument, new FileOutputStream(outputfilename));
    ^
    2 errors
    Same thing with running it. I could run it on one machine, but not another:
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/java/util/collections/Collection
    at org.jdom.input.DefaultJDOMFactory.document(DefaultJDOMFactory.java)
    at org.jdom.input.DOMBuilder.build(DOMBuilder.java)
    at org.bcit.mmsd.lab5.MyJDOMParser.<init>(MyJDOMParser.java:86)
    at org.bcit.mmsd.lab5.Controller.<init>(Controller.java:77)
    at org.bcit.mmsd.lab5.Controller.main(Controller.java:135)

    I've a similar problem. With this code:
    import org.jdom.*; // version 8 beta
    import org.jdom.input.*;
    public static void listChildren(org.jdom.Element current) {
    java.util.List children = current.getChildren();
    Iterator iterator = children.iterator();
    while (iterator.hasNext()) {
    Element child = (Element) iterator.next();
    listChildren(child);
    compiled on NetBeans 3.4, I've got this error:
    incompatible types:
    found : com.sun.java.util.collections.Iterator
    required: java.util.Iterator
    Iterator iterator = children.iterator();
    ????????

  • Problem in using org.jdom.Parent in my EJB

    Hi All,
    I am using a code below to read a EBM and replace some of the node values in it. For that , initiallly, i want to check whether the XPATH class is working ..
    While i run this code in my SOAP-UI i get teh No class definition found exception for the class org.jdom.Parent. But i hav imported that jar inside my project. and i am able to use the line import org.jdom.parent. in my class file.
    package EBMhandling;
    import java.io.StringReader;
    import javax.jws.WebService;
    import java.io.StringReader;
    import javax.jws.WebService;
    import org.jdom.Document;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.XMLOutputter;
    import org.jdom.xpath.XPath;
    import org.xml.sax.InputSource;
    import org.jdom.Parent;
    @WebService
    public class UsingJDOMclass {
    public String ReplaceEBM(String input,String nodeXpath) {
    String modifiedEBM=null;
    try
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build( new InputSource(new StringReader(input)) );
    modifiedEBM=(new XMLOutputter()).outputString(doc);
    // String innerXml = (new XMLOutputter()).outputString(XPath.selectSingleNode(doc,nodexpath));
    try
    XPath myxpath=XPath.newInstance(nodeXpath);
    modifiedEBM=myxpath.toString();
    catch(Exception e) {
    modifiedEBM="ERROR: inside :" + e.toString();
    catch(Exception e) {
    modifiedEBM="ERROR :" + e.toString();
    return modifiedEBM;
    This is the error i get:
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns2:ReplaceEBMResponse xmlns:ns2="http://EBMhandling/">
    <return>ERROR: inside :org.jdom.JDOMException: java.lang.NoClassDefFoundError: org/jdom/Parent: org/jdom/Parent</return>
    </ns2:ReplaceEBMResponse>
    </S:Body>
    </S:Envelope>
    Kindly help me in this regard.
    Thanks,
    Sabarisri. N

    Hi Sameera,
    I found the conflict is because that, i hav added two different jars to my project folder. Both the jars contiained the definition of the class org.jdom.parent.
    So why the error have occured. I came to know a solution defined in https://issues.apache.org/jira/browse/GERONIMO-3894
    Not sure.. hw well it would work..
    So i think i can go for some alternative classes.
    Can u pls help me in the below requirement.
    I need to get a method which take input as (XMLasString,xpathOfElement,NewValueForThatElement)
    I shd replace the old value of that element by the NewValueForThatElement and again return back the XMLasString only..
    Thanks,
    Sabarisri. N

  • Problem parsing a xml using Jdom

    Hi all,
    I am reposting it as I was told to format the code and send it again.
    I am trying to parse a xml file using a jdom java code.This code works fine if I remove xmlns attribute in the root element. (I get the expected result) .If the "xmlns" attribute is put in the xml as it should be then the parsing and retrieving returns null. Please tell me how to fix this issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Xml
    <process name="CreateKBEntryService" targetNamespace="http://serena.com/CreateKBEntryService" suppressJoinFailure="yes" xmlns:tns="http://serena.com/CreateKBEntryService" xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:nsxml0="http://localhost:8080/axis/services/CreateKBEntryService" xmlns:nsxml1="http://DefaultNamespace" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <partnerLinks>
    <partnerLink name="client" partnerLinkType="tns:CreateKBEntryService" myRole="CreateKBEntryServiceProvider"/>
    <partnerLink name="CreateKBEntryPartnerLink" partnerLinkType="nsxml0:CreateKBEntryLink" partnerRole="CreateKBEntryProvider"/>
    </partnerLinks>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    Java:
    import java.io.*;
    import java.util.*;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    public class sample1 {
    public static void main(String[] args) throws Exception {
    // create a XML parser and read the XML file
    SAXBuilder oBuilder = new SAXBuilder();
    Document oDoc = oBuilder.build(new File("**xml file location**"));
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    List list= root.getChildren("partnerLinks");
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());
    while(it1.hasNext()){
    Element partnerlinks = (Element)it1.next();
    List list2= partnerlinks.getChildren("partnerLink");
    System.out.println("iterator 2 - "+list2.size());
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Result:
    Without Xmlns in xml file(Expected and correct output)
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 1//expected and correct result that comes when I remove xmlns attribute from xml
    iterator 2 - 2
    Result with xmlns:
    process
    tgt ns http://serena.com/CreateKBEntryService
    Iterator 1 - 0 //instead of 0 should return 1

    One suggestion to try:
    Change your code to the following
    Element root = oDoc.getRootElement();
    System.out.println(root.getName());
    String tgtns= root.getAttributeValue("targetNamespace");
    System.out.println("tgt ns "+ tgtns);
    Namespace ns = Namespace.getNamespace(
      "http://schemas.xmlsoap.org/ws/2003/03/business-process/" );
    List list= root.getChildren("partnerLinks", ns );
    Iterator it1= list.iterator();
    System.out.println("Iterator 1 - "+list.size());The JavaDoc says for the one-arg getChildren()
    If this target element has no nested elements with the given name outside a namespace, an empty List is returned.
    Your elements have a namespace (the default one) so it should be worth a try.
    Dave Patterson

  • Formatting problem with JDOM

    friends,
    help me out plz..
    While creating a xml document using JDOM ,
    I am not able to get the formatted xml file.
    program output is:
    <?xml version="1.0" encoding="UTF-8"?>
    <person><name>A</name><name>B</name><name>C</name><name>D</name></person>
    I want the result as:
    <?xml version="1.0" encoding="UTF-8"?>
    <person>
         <name>A</name>
         <name>B</name>
         <name>C</name>
         <name>D</name>
    </person>
    // XMLGenerator.java
    import org.jdom.Element;
    import org.jdom.Document;
    import org.jdom.output.XMLOutputter;
    import java.io.*;
    public class XMLGenerator {
    public static void main(String[] args) throws Exception{
    Element root = new Element("employee");
    while(rs.next()) // rs .. ResultSet
    Element emp_name= new Element("name");
    emp_name.setText(rs.getString(rs.getString("name")));
    root.addContent(emp_name);
    Document doc = new Document(root);
    // serialize it into a file
    try {
    FileOutputStream out = new FileOutputStream("record.xml");
    XMLOutputter serializer = new XMLOutputter();
    serializer .setIndent(true);
    serializer.output(doc, out);
    out.flush();
    out.close();
    catch (IOException e) {
    System.err.println(e);

    try:
    XMLOutputter serializer = new XMLOutputter( " " );
    with the size of the indent you require.
    You dont really need the line: serializer.setIndent(true); if u use this constructor.
    Hope this Helps
    Sam

Maybe you are looking for

  • How can i use an barcode scanner and a keyboard at the same time on Ipad

    HI I am looking to find a way to use a barcode scanner and the on screen key bard at the same time, so far i cant seem to find a way to do it. Does any one know how this can be done. thanks

  • How do I import a PDF with typewriter objects?

    I have a saved .pdf with text created by the typewriter tool. When I import the .pdf in InDesign (I'm using CS4), the typewriter text disappears in the InDesign document. I cannot find any preferences or settings in either Acrobat or InDesign that so

  • SOAP 1.2 binding

    Hello, My question: Why BPEL is not using SOAP 1.2 name space "http://www.w3.org/2003/05/soap-envelope", instead its using soap 1.1 "http://schemas.xmlsoap.org/soap/envelope/" ? I am developing BPEL on 10.1.3.1. My WSDL file contain <service name="PM

  • How to include .java file in all projects?

    Hi Friends, i have some questions related.... 1) i have a file .java with some great functions, this functions i need use in all projects, then what is the easy by moment i start a project, and copy this file to project..   is possible have only 1 fi

  • Oracle 9.2.0.8 , decrease db_cache_size ,but OS hasn't freed those memory

    hi, anyone ever had the same expierence as me , succeeded in alter system set db_cache_size to a smaller value , and query from v$buffer_pool shows clearly it's in effect now , but , somehow , OS memory utiliztion are still as high as before . anyway