Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java xml basic questions

Reply
Thread Tools

Java xml basic questions

 
 
Rolf.Kemper@eu.necel.com
Guest
Posts: n/a
 
      05-01-2007
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

 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      05-01-2007
On May 1, 7:52 am, (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      05-01-2007
In article <(E-Mail Removed). com>,
Daniel Pitts <(E-Mail Removed)> wrote:

> On May 1, 7:52 am, (E-Mail Removed) 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.XMLSeria lizer.
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
 
Reply With Quote
 
Rolf.Kemper@eu.necel.com
Guest
Posts: n/a
 
      05-01-2007
On 1 Mai, 17:30, Daniel Pitts <(E-Mail Removed)> wrote:
> On May 1, 7:52 am, (E-Mail Removed) 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



 
Reply With Quote
 
wisccal@googlemail.com
Guest
Posts: n/a
 
      05-02-2007
On May 1, 1:39 pm, (E-Mail Removed) wrote:
> On 1 Mai, 17:30, Daniel Pitts <(E-Mail Removed)> wrote:
>
>
>
> > On May 1, 7:52 am, (E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
my thread of basic Java questions denim_genes@hotmail.com Java 22 04-24-2008 09:07 AM
Clicking on Sun Java Plugin installation evokes 3 basic java setup questions Bonnie Johnson Java 2 01-10-2007 10:13 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Java install on Linux FC4 (Two very basic questions). AnonymousFC4 Java 3 07-29-2005 12:05 AM
Basic XML questions... Unal XML 3 11-01-2004 10:58 PM



Advertisments