Java xml basic questions

Discussion in 'Java' started by Rolf.Kemper@eu.necel.com, May 1, 2007.

  1. Guest

    Dear Java experts,

    I'm Java beginner , but xml experienced.
    I'm working with:

    java version "1.5.0_11"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

    or later version.

    I would like to write a dom tree to an xml file.
    If possible I would like to avoid additional installation of Java
    classes.

    Is the following class not is the standard distribution ?

    import org.apache.xml.serialize.XMLSerializer;

    I get package org.apache.xml.serialize does not exist !

    What could be wrong ?
    If it can not work without installation of new classes, what is the
    best option ?

    Thanks a lot

    Rolf
    , May 1, 2007
    #1
    1. Advertising

  2. Daniel Pitts Guest

    On May 1, 7:52 am, wrote:
    > Dear Java experts,
    >
    > I'm Java beginner , but xml experienced.
    > I'm working with:
    >
    > java version "1.5.0_11"
    > Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    > Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
    >
    > or later version.
    >
    > I would like to write a dom tree to an xml file.
    > If possible I would like to avoid additional installation of Java
    > classes.
    >
    > Is the following class not is the standard distribution ?
    >
    > import org.apache.xml.serialize.XMLSerializer;
    >
    > I get package org.apache.xml.serialize does not exist !
    >
    > What could be wrong ?
    > If it can not work without installation of new classes, what is the
    > best option ?
    >
    > Thanks a lot
    >
    > Rolf


    org.apache classes probably come from apache.org. I'm guessing thats
    part of Xerces, but I don't know for certain... It is not standard,
    but easy to bundle.
    Daniel Pitts, May 1, 2007
    #2
    1. Advertising

  3. In article <>,
    Daniel Pitts <> wrote:

    > On May 1, 7:52 am, wrote:
    > > Dear Java experts,
    > >
    > > I'm Java beginner , but xml experienced.
    > > I'm working with:
    > >
    > > java version "1.5.0_11"
    > > Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    > > Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
    > >
    > > or later version.
    > >
    > > I would like to write a dom tree to an xml file.
    > > If possible I would like to avoid additional installation of Java
    > > classes.
    > >
    > > Is the following class not is the standard distribution ?
    > >
    > > import org.apache.xml.serialize.XMLSerializer;
    > >
    > > I get package org.apache.xml.serialize does not exist !
    > >
    > > What could be wrong ?
    > > If it can not work without installation of new classes, what is the
    > > best option ?
    > >
    > > Thanks a lot
    > >
    > > Rolf

    >
    > org.apache classes probably come from apache.org. I'm guessing thats
    > part of Xerces, but I don't know for certain... It is not standard,
    > but easy to bundle.


    The Apache Xerces and Xalan classes are bundled as of 1.5. They're
    simply moved to another package hierarchy in order to allow users the
    ability to use newer releases from Apache should they wish.

    But they're not all listed in the Javadocs, including XMLSerializer.
    It's now at com.sun.org.apache.xml.internal.serialize.XMLSerializer.
    Note the "com.sun" prefix and the addition of "internal". Poke around
    in the src.zip with the JDK installation.

    = Steve =
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, May 1, 2007
    #3
  4. Guest

    On 1 Mai, 17:30, Daniel Pitts <> wrote:
    > On May 1, 7:52 am, wrote:
    >
    >
    >
    >
    >
    > > Dear Java experts,

    >
    > > I'm Java beginner , but xml experienced.
    > > I'm working with:

    >
    > > java version "1.5.0_11"
    > > Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    > > Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

    >
    > > or later version.

    >
    > > I would like to write a dom tree to an xml file.
    > > If possible I would like to avoid additional installation of Java
    > > classes.

    >
    > > Is the following class not is the standard distribution ?

    >
    > > import org.apache.xml.serialize.XMLSerializer;

    >
    > > I get package org.apache.xml.serialize does not exist !

    >
    > > What could be wrong ?
    > > If it can not work without installation of new classes, what is the
    > > best option ?

    >
    > > Thanks a lot

    >
    > > Rolf

    >
    > org.apache classes probably come from apache.org. I'm guessing thats
    > part of Xerces, but I don't know for certain... It is not standard,
    > but easy to bundle.- Zitierten Text ausblenden -
    >
    > - Zitierten Text anzeigen -


    Daniel,
    thanks for your mail. Based on the little I know your understanding is
    right. I think XERCES is part of standard distribution.
    This is why I'm a bit pussled that XMLSerializer is obviously not.
    Meantime I found a solution by using TransformerFactory and DomSource.
    But I have not finalized it yet.

    The part I'struggling is the following:

    I have created a Nodelist out of an XML docuemnt by Xpath which works
    well.
    // snipet
    NodeList Config = (NodeList )xpath.evaluate("/ShotMapConfigs/
    Config[@Name='" + "uCFL_V1.0" + "']", DocConfigXML ,
    XPathConstants.NODESET )
    // end snipet

    Next I tried to add a single node out of this list to a NEW dom
    document.
    I get an error that the nodes are not from the same document.
    Basically I undestand that.
    I tried to use DocumentFragment , but this does not help.
    // snipet
    Document doc = impl.createDocument(null,"ShotMapDocLog", null);
    DocumentFragment fragment = doc.createDocumentFragment();
    fragment.appendChild(Config.item(0));
    Element root = doc.getDocumentElement();
    // end snipet

    So , the question on this is how can I let's say copy a fragment from
    one dom to another ?
    Any idea is welcome.

    Rolf
    , May 1, 2007
    #4
  5. Guest

    On May 1, 1:39 pm, wrote:
    > On 1 Mai, 17:30, Daniel Pitts <> wrote:
    >
    >
    >
    > > On May 1, 7:52 am, wrote:

    >
    > > > Dear Java experts,

    >
    > > > I'm Java beginner , but xml experienced.
    > > > I'm working with:

    >
    > > > java version "1.5.0_11"
    > > > Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    > > > Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

    >
    > > > or later version.

    >
    > > > I would like to write a dom tree to an xml file.
    > > > If possible I would like to avoid additional installation of Java
    > > > classes.

    >
    > > > Is the following class not is the standard distribution ?

    >
    > > > import org.apache.xml.serialize.XMLSerializer;

    >
    > > > I get package org.apache.xml.serialize does not exist !

    >
    > > > What could be wrong ?
    > > > If it can not work without installation of new classes, what is the
    > > > best option ?

    >
    > > > Thanks a lot

    >
    > > > Rolf

    >
    > > org.apache classes probably come from apache.org. I'm guessing thats
    > > part of Xerces, but I don't know for certain... It is not standard,
    > > but easy to bundle.- Zitierten Text ausblenden -

    >
    > > - Zitierten Text anzeigen -

    >
    > Daniel,
    > thanks for your mail. Based on the little I know your understanding is
    > right. I think XERCES is part of standard distribution.
    > This is why I'm a bit pussled that XMLSerializer is obviously not.
    > Meantime I found a solution by using TransformerFactory and DomSource.
    > But I have not finalized it yet.
    >
    > The part I'struggling is the following:
    >
    > I have created a Nodelist out of an XML docuemnt by Xpath which works
    > well.
    > // snipet
    > NodeList Config = (NodeList )xpath.evaluate("/ShotMapConfigs/
    > Config[@Name='" + "uCFL_V1.0" + "']", DocConfigXML ,
    > XPathConstants.NODESET )
    > // end snipet
    >
    > Next I tried to add a single node out of this list to a NEW dom
    > document.
    > I get an error that the nodes are not from the same document.
    > Basically I undestand that.
    > I tried to use DocumentFragment , but this does not help.
    > // snipet
    > Document doc = impl.createDocument(null,"ShotMapDocLog", null);
    > DocumentFragment fragment = doc.createDocumentFragment();
    > fragment.appendChild(Config.item(0));
    > Element root = doc.getDocumentElement();
    > // end snipet
    >
    > So , the question on this is how can I let's say copy a fragment from
    > one dom to another ?
    > Any idea is welcome.
    >
    > Rolf


    I believe all that you have to do is to import the node first, which
    creates a copy that can be inserted into the new Document. Something
    like:

    Node node = doc.importNode(Config.item(0), true); //true to deep-copy
    ....
    fragment.appendChild(node);

    Also, I would recommend that you use the various factory classes
    instead of the vendor-specific implementations. I.e., instead of
    impl.createDocument(), use DocumentBuilderFactory & DocumentBuilder to
    parse or to create a new Document.

    Hope this proves helpful.

    Steve
    ------------
    www.stkomp.com
    , May 2, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AnonymousFC4
    Replies:
    3
    Views:
    476
    Knute Johnson
    Jul 29, 2005
  2. Unal

    Basic XML questions...

    Unal, Oct 29, 2004, in forum: XML
    Replies:
    3
    Views:
    588
    Peter Flynn
    Nov 1, 2004
  3. Engineer
    Replies:
    6
    Views:
    605
    Jeremy Bowers
    May 1, 2005
  4. Bonnie Johnson
    Replies:
    2
    Views:
    491
    Andrew Thompson
    Jan 10, 2007
  5. Replies:
    22
    Views:
    733
    Roedy Green
    Apr 24, 2008
Loading...

Share This Page