Transform DOM as XML ????????
Hi Friends
I have created a DOM for an XML file and then I edited that DOM.
Now Please if it is possible to TRANSFORM that DOM again as an XML file instead of HTML file.
One mode thing if i have a dom and I want to add CDATA to specific NODE how do we do it .. Please let me know.
Any help would be great.
Thanks
How to add a CDATA section to a NODE, provided that the DTD allows a CDATA section to be added to a NODE you can do the following:
This is the general idea: you will have to check if it compiles.
//Create a CharacterData node from a Document. The document represents a DOM which was either created from an xml file or is being created on the file.
CharacterData cdata = document.createCDATASection("The character data");
//Find the node that you want by using a search algorithm:
public boolean findNode(Node root, String elementName,
CharacterData cdata){
if(root instanceof Text){
System.out.println("element is a text node");
return false;
//if you have found the node with local name ==
//elementName. Then append the cdatasection as a
//child
if(root.getLocalName().equals(elementName)){
System.out.println("Found Node");
root.appendChild(cdata);
return true;
if(!root.hasChildNodes()){
System.out.println("element has no children");
return false;
//Run through the children for root and for each //recursively see if any of their children is the desired node.
NodeList childNodes = root.getChildNodes();
int noChildren = childNodes.getLength();
boolean result = false;
for(int i = 0; i<noChildren; i++){
if(!result){
System.out.println("About to find next child");
result = findNode(childNodes.item(i),
elementName, cdata);
}else break;
return result;
Hope this helps.
Similar Messages
-
Losing "xmlns" when transforming DOM to XML file in OC4J
I am outputting a DOM to a file using the standard transformation approach. When executed within JDeveloper everything works fine. However, when wrapped in a webservice using JDeveloper and run within OC4J the output is missing the "xmlns" attribute from the root node. Anyone have an idea why this is happening and what a workaround would be?
The original XML root element is:
<e2579ReportAssemblyList xmlns="http://cdrh.fda.gov/schema/e2579ReportAssembly.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="http://cdrh.fda.gov/schema/e2579ReportAssembly.xsd e2579ReportAssembly.xsd">
You can see the xmlns attribute has been provide. I have verified that the attributes are correct while in the DOM.
The xml root element after saving to DOM using transformation is:
<e2579ReportAssemblyList xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="http://cdrh.fda.gov/schema/e2579ReportAssembly.xsd e2579ReportAssembly.xsd">
You can see the xmlns attribute is now blank.
The approach used in the transformation is as follows:
File mOutput = new File(mFileNamePath);
FileOutputStream mOutputStream = new FileOutputStream(mOutput);
Transformer mTransformer = TransformerFactory.newInstance().newTransformer();
mTransformer.transform(new DOMSource(mNextBatchItem), new StreamResult(mOutputStream));
mOutputStream.close();
Any suggestions would be greatly appreciated.If no one knows why this is happening in the transform, is there another reliable way of outputting the DOM to an XML file?
-
Hello,
I build a DOM tree in my applet.
Then I transform it to XML String.
But since the JRE 1.4.2_05 it doesn't work.
These lines failed because these variables became final:
org.apache.xalan.serialize.CharInfo.XML_ENTITIES_RESOURCE = getClass().getResource("XMLEntities.res").toString();
org.apache.xalan.processor.TransformerFactoryImpl.XSLT_PROPERTIES = getClass().getResource("XSLTInfo.properties").toString();The rest of the code :
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document domXML = builder.newDocument();
// I build my DOM Tree
StringWriter xmlResult = new StringWriter();
Source source = new DOMSource(domXML);
Result result = new StreamResult(xmlResult);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT,"yes");
xformer.transform(source,result);Is there any other way to get an XML String from a DOM tree in an applet ?
I'm so disappointed to note this big problem.Does anyone have an idea why I get this error message when try to use transform in an applet?
Thanks...
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.xalan.serialize.SerializerFactory.getSerializer(Unknown Source)
at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(Unknown Source)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Unknown Source)
at matrix.CreateMtrx.SaveDoc(CreateMtrx.java:434)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at thinlet.Thinlet.invokeImpl(Unknown Source)
at thinlet.Thinlet.invoke(Unknown Source)
at thinlet.Thinlet.handleMouseEvent(Unknown Source)
at thinlet.Thinlet.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.RuntimeException: The resource [ XMLEntities.res ] could not load: java.net.MalformedURLException: no protocol: XMLEntities.res
XMLEntities.res java.net.MalformedURLException: no protocol: XMLEntities.res
at org.apache.xalan.serialize.CharInfo.<init>(Unknown Source)
at org.apache.xalan.serialize.SerializerToXML.<clinit>(Unknown Source)
... 28 more -
[Q] convert DOM to XML Document
Hi,
Is there any class or library which convert DOM to XML document?
----- java program ------------
import org.w3c.dom.*;
import org.apache.crimson.tree.XmlDocument;
public class Sample {
public static void main(String args[]) {
// create a document and root element
Document doc = new XmlDocument();
Element root = doc.createElement("html");
doc.appendChild(root);
// append a data
Element body = doc.createElement("body");
root.appendChild(body);
body.appendChild(doc.createTextNode("Hello"));
// convert DOM to XML Document
}----- expected result ----------
<html>
<body>
Hello
</body>
</html>Could you help me?Hi,
Look at the package javax.xml.transform
or
try the following code:
I tried the following code.
----- java program ------------
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.io.OutputStream;
public class Sample {
public static void main(String[] args) {
try {
// create a document and root element
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.newDocument();
Element root = doc.createElement("html");
doc.appendChild(root);
// append a data
Element body = doc.createElement("body");
root.appendChild(body);
body.appendChild(doc.createTextNode("Hello"));
Element ul = doc.createElement("ul");
String[] list = {"foo", "bar", "baz"};
for (int i=0; i<list.length; i++) {
Element li = doc.createElement("li");
li.appendChild(doc.createTextNode(list));
ul.appendChild(li);
body.appendChild(ul);
// convert DOM to XML Document
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
//OutputStream stream = new FileOutputStream("output.xml");
OutputStream stream = System.out;
transformer.transform(new DOMSource(doc), new StreamResult(stream));
} catch (Exception ex) {
ex.printStackTrace();
----- result ------------
<html>
<body>Hello<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
</body>
</html>Great! Very thanks! -
How to transform DOM into String
Hi,
Can any one provide an example of transforming DOM into String using TransformationFactory or any other API of JAXP?
Regards...
ShamitAnd for finer output:
* Prints a textual representation of a DOM object into a text string..
* @param document DOM object to parse.
* @return String representation of <i>document</i>.
static public String toString(Document document) {
String result = null;
if (document != null) {
StringWriter strWtr = new StringWriter();
StreamResult strResult = new StreamResult(strWtr);
TransformerFactory tfac = TransformerFactory.newInstance();
try {
Transformer t = tfac.newTransformer();
t.setOutputProperty(OutputKeys.ENCODING, "iso-8859-1");
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty(OutputKeys.METHOD, "xml"); //xml, html, text
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
t.transform(new DOMSource(document.getDocumentElement()), strResult);
} catch (Exception e) {
System.err.println("XML.toString(Document): " + e);
result = strResult.getWriter().toString();
return result;
}//toString() -
I am trying to create an XML file using DOM and a HashMap to enter data.
1- How can I link my HashMap to teh DOM code
2- Why FileWriter is printing only one line in the file
3- Am I missing something?
Thank you
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMSource;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import org.w3c.dom.*;
public class MyHashmap
public static void main(String[]args)
try
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element e= doc.createElement("names");
Text ee = doc.createTextNode("address");
doc.appendChild(e);
e.appendChild(e);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
DOMSource source= new DOMSource(doc);
StringWriter strwriter = new StringWriter();
StreamResult strresult = new StreamResult(strwriter);
transformer.transform(source,strresult);
String result = strwriter.toString();
FileWriter fw = new FileWriter("result.txt");
fw.write(result);
fw.close();
catch (ParserConfigurationException e1)
e1.printStackTrace();
catch (TransformerConfigurationException e)
e.printStackTrace();
catch (TransformerException e)
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
public void hashMap(String names, String address)
HashMap hmap = new HashMap();
MyHashmap mymap = new MyHashmap();
hmap.put("names", "address");
System.out.println(hmap.entrySet());
}to write nicely formatted XML use this:
FileOutputStream fos = new FileOutputStream(file);
TransformerFactory tf = TransformerFactory.newInstance();
try {
Transformer t = tf.newTransformer();
t.setOutputProperty("encoding", "iso-8859-1");
t.setOutputProperty("indent", "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource domsource = new DOMSource(document);
StreamResult sr = new StreamResult(fos);
t.transform(domsource, sr);
} catch (TransformerConfigurationException tce) {
tce.printStackTrace(System.err);
} catch (TransformerException te) {
te.printStackTrace(System.err); -
Can anyone help me in converting a dom to xml
hi,
i am facing a problem in using transformer factory to convert a dom to xml.
please help me.
if anyone has a sample code in java please share with me.static public void serialize( Document doc, File outFile)
try
TransformerFactory tfFac = TransformerFactory.newInstance();
Transformer tf = tfFac.newTransformer();
// tf.setOutputProperty("indent", "yes");
tf.transform(new DOMSource(doc),
new StreamResult(new FileWriter( outFile )
} // end of try
catch( FileNotFoundException fnfe )
System.err.println( "File Creation Error in serializer" );
System.err.println( fnfe.getMessage() );
} // end of catch
catch (TransformerException e)
e.printStackTrace();
} // end of catch
catch( IOException ioe )
System.err.println( "IOException in serializer" );
System.err.println( ioe.getMessage() );
} // end of catch
}Dave Patterson -
Simple Transformation ST, upload xml file to internal table
Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens?Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens? -
Simple Transformation - ABAP 2 XML
Dear all,
Finally I was able to transform an internal table to xml using ST. The question is: Can I create different structured XML-files using the same (structured) internal table. Or is there some kind of a 1:1 relationship (between an ITAB structure + XML structure)?
1) Data declaration
TYPES: BEGIN OF ty_curr,
tcurr TYPE tcurr_curr,
gdatu TYPE gdatu_inv,
ukurs TYPE ukurs_curr.
TYPES: END OF ty_curr.
DATA: gt_tcurr TYPE TABLE OF ty_curr.
2) Data selection
Select * into corresponding fields of table gt_tcurr from tcurr where...
3) Transformation ABAP 2 XML
CALL TRANSFORMATION z_tcurr
SOURCE root = gt_tcurr
RESULT XML g_xml_string.
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<tt:serialize>
<rates>
<tt:loop name="line" ref=".ROOT">
<currency>
<tt:value ref="$line.tcurr"/>
</currency>
<date>
<tt:value ref="$line.gdatu"/>
</date>
<rate>
<tt:value ref="$line.ukurs"/>
</rate>
</tt:loop>
</rates>
</tt:serialize>
</tt:template>
</tt:transform>
Result (XML)
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<currency>USD</currency>
<date>01.01.2010</date>
<rate>-1.1868</rate>
<currency>EUR</currency>
<date>01.01.2010</date>
<rate>-1.1791</rate>
<currency>USD</currency>
<date>02.01.2010</date>
<rate>-1.1864</rate>
<currency>EUR</currency>
<date>02.01.2010</date>
<rate>-1.1864</rate>
</rates>:
so far so good... BUT; if I want to get another XML structure
Example 1) -> sorted by currency
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<currency>USD
<date>01.01.2010</date>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<rate>-1.1868</rate>
</currency>
<currency>EUR
<date>01.01.2010</date>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<rate>-1.1868</rate>
</currency>
</rates>
Example 2) -> sored by date
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<date>01.01.2010</date>
<currency>USD</currency>
<rate>-1.1868</rate>
<currency>EUR</currency>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<currency>USD</currency>
<rate>-1.1868</rate>
<currency>EUR</currency>
<rate>-1.1868</rate>
</rates>
How can I achieve output example 1+2 using the same internal table as a source? Is this possible? I guess this can be solved within the transformation, right? Any help appreciated.
Best regards
BennoThanks for all answers so far. Changing the sequence is not a "problem". What I want to achieve is to change hierarchy of the xml. I'll try to explain again with a simple example:
ITAB (structure):
name; birthday; ***; first name
ITAB (content):
Smith; 01.01.1970; M; Paul
Smith; 01.01.1970; F; Stefanie
Smith; 01.02.1980; F; Barbara
White; 01.02.1980; M; Steve
I want to pass the itab exactly the way it is (ok, sorting is allowed). Question: Can I achieve the following XML's using ST? I guess/hope this can be solved with variables/groups/condition statements within the transformation coding?
Example xml- 1) Sorted/Grouped by Name/***
<person>
<name>Smith
<***>M
<birthday>01.01.1970</birthday><first name>Paul</first name>
</***>
<***>F
<birthday>01.01.1970</birthday><first name>Stefanie</first name>
<birthday>01.02.1980</birthday><first name>Barbara</first name>
</***>
</name>
<name>White
<***>M
<birthday>01.02.1980</birthday><first name>Steve</first name>
</***>
</name>
</person>
Exampe xml-2 ) Sorted/Grouped by Birthday (Names only)
<person>
<birthday>01.01.1970
<first name>Paul</first name>
<first name>Stefanie</first name>
</birthday>
<birthday>01.02.1980
<first name>Barbara</first name>
<first name>Steve</first name>
</birthday>
</person> -
Custom xml transformer provider for xml iview template
I have been trying to get a custom simple xml transformer to work, which will show up in the xml iview template. I have seen the SAP Help docs and the recent weblogs on the subject. I can't get this simple transform functionality to work. I can get as far as registering my own transformer, however I get an error on the page when trying to use it: "Error while using XML iView, please contact your system administrator." My understanding was all I needed to do was provide a xsl, a transformers.xml file, and a service reference in the portalapp.xml.
All I really want to do is take some xml docs I created and display them in the portal. I know that I can write a quick java app to do this myself. However, I am trying to use the built in functionality of the portal (which it appears no one is using except for RSS feeds).
I would prefer to have the output be htmlb from my xsl file. My understanding was that I should create my own xml tranformer provider and then also use the XHTMLB --> HTMLB built in transformer.
Has anyone been successful in trying to create their own xml transformer for the xml iView?
I am wasting a lot of time trying to use methods in the SAP Help Docs, is it worth the effort to use the transformer method?
Eager to award points,
SeanHi
I have successfully deployed a transformer by doing the following:
In PAR, in /dist/xml/XSLLibrary/Transformers, put XSL
In /dist/xml, put transformers.xml file that describes the XSL
In portalapp.xml, add registry entry for transformer and service entry for transformer service.
If you want, you can send transformer PAR and I can look at it ([email protected]).
There could be something wrong with the XSL; this would be more complicated to diagnose.
Daniel -
Creating Simple transformation for an XML data having deep structure
Hi
I have the following XML structure..
<REQUESTS>
<REQUESTNAME>REQ123</REQUESTNAME>
<REQUESTID>1234</REQUESTID>
<CITY>NEWYORK</CITY>
<ZIPCODE>123456</ZIPCODE>
<COMPETENCIES>
<LANGUAGES>
<COMPETENCY>
<SKILL>SAP</SKILL>
<PROFICIENCY>TEST</PROFICIENCY>
<SKILL>JAVA</SKILL>
<PROFICIENCY>TEST123</PROFICIENCY>
(here we may have any number of records for SKILL&PROFICIENCY...)*
</COMPETENCIES>
</LANGUAGES>
</COMPETENCY>
</REQUESTS>
My requirement is to read the above data from an URL and push it into an internal table.
For this I'm trying to use Simple transformations but I'm facing difficulty in doing this.
Can you pl. guide me how to create the transformation and the corresponding code for this.
Best Regards
AnilHi
Here is the actual XML structure..
- <REQUEST>
<COUNTRY />
<ADDRESS />
<CITY />
<ASSIGNTYPE>IP</ASSIGNTYPE>
<CHARGETYPE>CH</CHARGETYPE>
<REMOTEALLOWED>Y</REMOTEALLOWED>
<SALESRATE>EUR</SALESRATE>
<SECURITY>NO</SECURITY>
<TRAVELEXP>Y</TRAVELEXP>
<MAXDAILYRATE />
<CREDENTIALS />
<EXPENDDATE />
<NEWENDDATE />
<NEWEXPENDDATE />
<REPLYBEFORE>2010-11-30</REPLYBEFORE>
<STARTDATE>2010-01-01</STARTDATE>
<ENDDATE>2010-12-31</ENDDATE>
<GCMTYPE>PM</GCMTYPE>
<GCMLEVELFROM>02</GCMLEVELFROM>
<GCMLEVELTO>08</GCMLEVELTO>
<LOCATION>FR43</LOCATION>
<MOBILITY>04</MOBILITY>
<ZIPCODE />
- <COMPETENCIES>
- <LANGUAGES>
- <COMPETENCY>
<SKILL>01106034</SKILL>
<PROFICIENCY>005103</PROFICIENCY>
</COMPETENCY>
</LANGUAGES>
- <ACTIVITIES>
- <COMPETENCY>
<SKILL>01105500</SKILL>
<PROFICIENCY>004507</PROFICIENCY>
</COMPETENCY>
</ACTIVITIES>
- <BUSINESS>
- <COMPETENCY>
<SKILL>01105729</SKILL>
<PROFICIENCY>004605</PROFICIENCY>
</COMPETENCY>
</BUSINESS>
- <INDUSTRIES>
- <COMPETENCY>
<SKILL>01105491</SKILL>
<PROFICIENCY>004901</PROFICIENCY>
</COMPETENCY>
</INDUSTRIES>
- <METHODS>
- <COMPETENCY>
<SKILL>01105591</SKILL>
<PROFICIENCY>004805</PROFICIENCY>
</COMPETENCY>
</METHODS>
- <OFFERINGS>
- <COMPETENCY>
<SKILL>01105840</SKILL>
<PROFICIENCY>005002</PROFICIENCY>
</COMPETENCY>
</OFFERINGS>
- <PRODUCTS>
- <COMPETENCY>
<SKILL>01107304</SKILL>
<PROFICIENCY>004703</PROFICIENCY>
</COMPETENCY>
</PRODUCTS>
</COMPETENCIES>
<CANDIDATES />
</REQUEST>
Here..... <SKILL></SKILL> <PROFICIENCY></PROFICIENCY> can be more than 1 entry...
For this I have created a simple transformation like below..
I have used the tcode 'XSLT_TOOL '..
In SE11 I have created a Table type 'ZCOMPETENCIES' which is having a line type 'ZLANGS'.
ZLANGS is a structure which has another structure called 'ZCOMPETENCY' and this 'ZCOMPETENCY' is having fields
SKILL & PROFICIENCY.
I have used the wizard button which u can find 'XSLT_TOOL '.. and provided the table type ZCOMPETENCIES' and it has automatically created the following transformation...
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="ROOT" type="?"/>
<tt:root name="COMPETENCIES" type="ddic:ZCOMPETENCIES"/>
<tt:template>
<COMPETENCIES>
<tt:loop ref=".COMPETENCIES">
<ZLANGS>
<COMPETENCY>
<SKILL tt:value-ref="COMPETENCY.SKILL"/>
<PROF tt:value-ref="COMPETENCY.PROF"/>
</COMPETENCY>
</ZLANGS>
</tt:loop>
</COMPETENCIES>
</tt:template>
</tt:transform>
I have written following code to get the data
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gs_file
CHANGING
data_tab = gt_itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
GET REFERENCE OF gt_person INTO gs_result_xml-value.
gs_result_xml-name = 'COMPETENCIES'.
APPEND gs_result_xml TO gt_result_xml.
TRY.
CALL TRANSFORMATION ZTEST_TRAN
SOURCE XML gt_itab
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
Please let me know if you need any further details..
Best Regards
Anil -
Frmf2xml.sh: why do i need a display variable set to transform fmb to xml?
hallo,
why do i need a display variable set to transform fmb to xml with a shell script (frmf2xml.sh) ?
OS: SunOS 5.10
Oracle Forms Developer: 10.1.2
thank you
christianHi DrClap,
I just wanted to check with you whether I understood your comment correctly.
It's not possible to directly specify a physical file location path, like it is specified for HTTP URL +<c:import url= http://...+, that would internally/automatically convert in one of the form - Reader, Source, Document, String.
It can only be produced/specified explicitly in one of the form - Reader, Source, Document, String.
Am I correct in my understanding?
Regards,
Gnanam -
Hi,
I have some *.jsp files wich I have to transform into xml and xsl pages.
Can anyone help me with his advice?
And maybe someone knows a handy tool to transform jsp into xml?Refer to
http://developer.java.sun.com/developer/technicalArticles/xml/WebAppDev2/ -
HTML held in DOM (as XML) rendered onto JEditorPane
I am interested to know if anyone out there has any ideas on the following?:
I am holding an html document as a DOM object as it is part of an xml message (which undergoes various transformations) that is passed through our software.
The problem is that to do this I have had to make the html into a 'well-formed' xml document (which doesn't conform to html 3.2)
Basically this causes problems where I want to use html elements that forbid end tags (e.g. <br> or <img>), in that the DOM when written out contains these end tags (so <br> becomes <br></br> or
This actually works fine in IE (as it's quite lenient to these things) but when you put it in a JEditorPane it displays a spare > (not quite sure on it's logic!).
So... does anyone have any good ideas?? My only thought was to extend the HTMLEditorToolKit to be more lenient with these but that strikes me as being a bit hard! I know I can get around it by putting spaces in for things like img (e.g. <img src="bla.gif"> </img> displays fine whereas <img src="bla.gif"></img> displays the image and then a > symbol!)If anyone is still interested in this tread, an article was written on this subject and ways to work around it:
http://www.xml.com/pub/a/2000/08/30/xsltandhtml -
How to validate and transform large (180M) xml files
Hi:
I've been looking at various ways to do this with oracle and am getting a bit lost in the sea of documentation and different ways to go about this. I was hoping that something like the XMLParser class and XMLTransform would be smart enough to handle large files by using SAX when it has to but I'm getting "too many nodes" when trying to transform a really large file. I've gotten oraxsl to handle it if I pass in the proper memory parameters on the command line but a) this will still have limits and b) I was trying to do this in a stored procedure which (I think) means I'm looking at XMLParser?
I've also seen documentation on something called "Scalable DOM" but I think that's only in 11g? So I'm thinking I have to write a (Java?) stored procedure to loop through the top elements of this XML file (select extract(...)) and transform each node?
I have the XML, XSD, and XSLT all in clob columns. What's the easiest/quickest path within Oracle to validate the XML against the xsd and translate source XML with XSL?
I'm using Oracle 10gR2 on RH Linux.
Thanks.So I'm thinking I have to write a (Java?) stored procedure to loop through the top elements of this XML file (select extract(...)) and transform each node? Here's something I've written a while back when I hit the same restrictions ("too many nodes") on 10.2.0.4.
It takes XMLType as input parameters (but it's easy to adapt for CLOB), and streams the transformed XML directly into a file :
create or replace and compile java source named ora_xslt_util as
import oracle.xml.parser.v2.*;
import oracle.xdb.XMLType;
import java.io.*;
import org.w3c.dom.*;
public class oraXSL
private static XMLDocument getXMLDocument(XMLType xml) throws Exception
XMLDocument doc = null;
DOMParser parser = new DOMParser();
parser.setValidationMode(oracle.xml.parser.v2.XMLParser.NONVALIDATING);
parser.setPreserveWhitespace(true);
parser.parse(new StringReader(xml.getStringVal()));
doc = parser.getDocument();
return doc;
public static void transform(XMLType doc, XMLType xsl, String filename) throws Exception
OutputStream os = new FileOutputStream(filename);
XMLDocument xmldoc = getXMLDocument(doc);
XMLDocument xsldoc = getXMLDocument(xsl);
XSLProcessor xsp = new XSLProcessor();
XSLStylesheet xss = xsp.newXSLStylesheet(xsldoc);
xsp.processXSL(xss, xmldoc, os);
os.close();
}and the PL/SQL wrapper (originally part of a package) :
PROCEDURE processXSL (
p_xmldoc IN XMLType
, p_xsldoc IN XMLType
, p_filename IN VARCHAR2
IS
LANGUAGE JAVA NAME 'oraXSL.transform(oracle.xdb.XMLType,oracle.xdb.XMLType,java.lang.String)'
;
Maybe you are looking for
-
There may be more errors in here besides the static variable error. I made the methods static for the method call in my constructor Product(name, price). The purpose of this Class is to the the name and price of a product from user input, subtract 5.
-
IMovie 10 static standard title?
When I choose "standard" for the title, the title gets a Ken Burns effect. How can I get a static title--just white font on a black background?
-
DML_FETCH_ROW with flashback?
I love the ability to query tables using flashback and select * from TABLE as of pre-bonehead, but using a Form on Report, I can't have that flashback apply to a form that uses automatic row processing.<p> I even dug through the apex scripts a bit to
-
NullPointerException during InitialContext creation in RJVMFinder (WL 5.1)
Has anyone seen this NPE when creating an InitialContext? We got this for about a day on one of our cluster instances, and then it magically went away (the other server in the cluster worked fine).. Solaris, Weblogic 5.1 service pack 10. java.lang.Nu
-
How do I link two icloud emails to one?
I have my old email linked to my phone and my new email linked to iPad...Can you tell me how to merge them to one email and one icloud??