You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by William Lane <wl...@aessuccess.org> on 2002/04/15 19:20:20 UTC
really stupid question....
I am working on an application that takes an XML file parses it into 3
COBOL flat files. the COBOL files get Processed then come back to me.
When we get those files back im suppose to create a new xml document parse
the data into it and then ship it off.
well i cant for the life of me figure out how to get Xerces to make me a
new XML document. is there anyone out there who could help me? i am really
new to XML and Xerces.
i am using Java with JDK as my develpment kit.
any help would be appreciated.
Bill Lane
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: really stupid question....
Posted by Andy Clark <an...@apache.org>.
William Lane wrote:
> well i cant for the life of me figure out how to get Xerces to make me a
> new XML document. is there anyone out there who could help me? i am really
> new to XML and Xerces.
Also look into the javax.xml.parsers interfaces that are
part of JAXP (and that is implemented by Xerces). There is a
method to create an empty DOM document that your application
can build up programmatically. In this way you can avoid
putting a dependency on the Xerces DOM implementation in
your code.
--
Andy Clark * andyc@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
RE: really stupid question....
Posted by Doug Helton <dh...@ideorlando.org>.
Hi,
If You download the source code they have some good examples. If you look
at DOMGenerate it goes through the process of creating a new document. It
creates the root element and an element to attach to it.If you wanted to add
attributes to item you would simply do item.setAttribute("something",
"value") before adding it to the root. Here is a copy of DOMGenerator if you
don't want to down load it:
package dom;
import org.w3c.dom.*;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.DOMImplementationImpl;
import org.w3c.dom.Document;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.apache.xml.serialize.XMLSerializer;
import java.io.*;
public class DOMGenerate {
public static void main( String[] argv ) {
try {
Document doc= new DocumentImpl(); // new document
Element root = doc.createElement("person"); // Create Root
Element
Element item = doc.createElement("name"); // Create
element
item.appendChild( doc.createTextNode("Jeff") ); //
<name>jeff</name>
root.appendChild( item ); // atach element
to Root element
item = doc.createElement("age"); // Create
another Element
item.appendChild( doc.createTextNode("28" ) );
root.appendChild( item ); // Attach
Element to previous element down tree
item = doc.createElement("height");
item.appendChild( doc.createTextNode("1.80" ) );
root.appendChild( item ); // Attach
another Element - grandaugther
doc.appendChild( root ); // Add Root to
Document
OutputFormat format = new OutputFormat( doc ); //Serialize
DOM
StringWriter stringOut = new StringWriter(); //Writer
will be a String
XMLSerializer serial = new XMLSerializer( stringOut,
format );
serial.asDOMSerializer(); // As a DOM
Serializer
serial.serialize( doc.getDocumentElement() );
System.out.println( "STRXML = " + stringOut.toString() ); //Spit
out DOM as a String
} catch ( Exception ex ) {
ex.printStackTrace();
}
}
}
Doug Helton
-----Original Message-----
From: William Lane [mailto:wlane@aessuccess.org]
Sent: Monday, April 15, 2002 1:20 PM
To: xerces-j-user@xml.apache.org
Subject: really stupid question....
I am working on an application that takes an XML file parses it into 3
COBOL flat files. the COBOL files get Processed then come back to me.
When we get those files back im suppose to create a new xml document parse
the data into it and then ship it off.
well i cant for the life of me figure out how to get Xerces to make me a
new XML document. is there anyone out there who could help me? i am really
new to XML and Xerces.
i am using Java with JDK as my develpment kit.
any help would be appreciated.
Bill Lane
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org