Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Java xml basic questions

Thread view: 
Rolf.Kemper@eu.necel.com - 01 May 2007 15:52 GMT
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
Daniel Pitts - 01 May 2007 16:30 GMT
On May 1, 7:52 am, Rolf.Kem...@eu.necel.com wrote:
> Dear Java experts,
>
[quoted text clipped - 24 lines]
>
> 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.
Steve W. Jackson - 01 May 2007 18:36 GMT
> On May 1, 7:52 am, Rolf.Kem...@eu.necel.com wrote:
> > Dear Java experts,
[quoted text clipped - 29 lines]
> 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 =
Signature

Steve W. Jackson
Montgomery, Alabama

Rolf.Kemper@eu.necel.com - 01 May 2007 18:39 GMT
> On May 1, 7:52 am, Rolf.Kem...@eu.necel.com wrote:
>
[quoted text clipped - 32 lines]
>
> - 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
wisccal@googlemail.com - 02 May 2007 15:02 GMT
On May 1, 1:39 pm, Rolf.Kem...@eu.necel.com wrote:

> > On May 1, 7:52 am, Rolf.Kem...@eu.necel.com wrote:
>
[quoted text clipped - 67 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.