Returning XML Document
I am having trouble (weblogic 7.0) exposing an EJB web service. It
takes string parameters in and should return an XML document. I've
ported this from apache axis, the java method takes java.lang.String
parameters and returns org.w3c.dom.Element ... this works fine on
Jboss 3.2.0. Can anyone help me figure out how to do the same on
weblogic? My web-services.xml file is as follows now:
<web-services>
<web-service name="myService"
targetNamespace="http://www.bobo.com"
uri="/jboss-net/services/myService">
<components>
<stateless-ejb name="myService">
<ejb-link
path="myjarfile.jar#MyServiceService"/>
</stateless-ejb>
</components>
<operations>
<operation name="runQuery"
invocation-style="request-response" component="myService" >
<params>
<param name="in0" style="in"
type="xsd:string" location="header"/>
<param name="in1" style="in"
type="xsd:string" location="header"/>
<param name="in2" style="in"
type="xsd:string" location="header"/>
<param name="in3" style="in"
type="xsd:string" location="header"/>
<return-param name="result"
type="xsd:anyType"/>
</params>
</operation>
</operations>
</web-service>
</web-services>
Feel free to respond to the group or to [email protected]
John
Hello,
Are you using servicegen against the EJB?
http://edocs.bea.com/wls/docs81/webserv/anttasks.html#1063540
Using a stateless session EJB example can be found here:
http://webservice.bea.com/statelessSession.zip and there is a dom
example here: http://webservice.bea.com/dom.zip
Thanks,
Bruce
Hauss wrote:
>
I am having trouble (weblogic 7.0) exposing an EJB web service. It
takes string parameters in and should return an XML document. I've
ported this from apache axis, the java method takes java.lang.String
parameters and returns org.w3c.dom.Element ... this works fine on
Jboss 3.2.0. Can anyone help me figure out how to do the same on
weblogic? My web-services.xml file is as follows now:
<web-services>
<web-service name="myService"
targetNamespace="http://www.bobo.com"
uri="/jboss-net/services/myService">
<components>
<stateless-ejb name="myService">
<ejb-link
path="myjarfile.jar#MyServiceService"/>
</stateless-ejb>
</components>
<operations>
<operation name="runQuery"
invocation-style="request-response" component="myService" >
<params>
<param name="in0" style="in"
type="xsd:string" location="header"/>
<param name="in1" style="in"
type="xsd:string" location="header"/>
<param name="in2" style="in"
type="xsd:string" location="header"/>
<param name="in3" style="in"
type="xsd:string" location="header"/>
<return-param name="result"
type="xsd:anyType"/>
</params>
</operation>
</operations>
</web-service>
</web-services>
Feel free to respond to the group or to [email protected]
John
Similar Messages
-
Webservices: returning xml document to client
Can anyone please help me to the following problem.
1. I have a java bean which i publish as webservice. I want to return an xml document on request from client(for time being my client is normal java client). when i call getDoc() from client i get classload exception. can anyone explain me why?
public org.w3c.dom.Document getDoc() throws java.rmi.RemoteException {
Document document = null;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( new File("C:\\data\\RND\\XmlParser\\XmlParser\\src\\xmlparser\\employer.xml"));
catch (Exception ex) {
return document;
2. if i have to send a xml file to clinet on request using web services(i assume i cant return an document as above), is it feasible(my xml file is a transaction file) to send a xml file as string?
3. how to transfer a xml file into a string?I'm almost sure that the error is because the Document class is not supported by JAX-RPC (see page 384 of the Java Web Services Tutorial).
Try sending your XML as a String.
This code may help you to transform between XML and String and viceversa:
import javax.xml.parsers.*;
import javax.xml.transform.*;
import org.xml.sax.*;
import org.w3c.dom.*;
public static Document toXmlDocument(String xml) throws IOException, SAXException, ParserConfigurationException
StringReader reader = new StringReader(xml);
InputSource source = new InputSource(reader);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document xmlDoc = builder.parse(source);
return ( xmlDoc );
public static String toXmlString(Node node) throws TransformerConfigurationException, TransformerException
StringWriter writer = new StringWriter();
DOMSource source = new DOMSource(node);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
StreamResult result = new StreamResult(writer);
transformer.transform(source,result);
return ( writer.toString() );
} -
Return XML document through Web Service?
Hello,
Is it possible to return a XML document from a web service?
For example, I have a Oracle Report that outputs in XML format, is it possible to return that through a web service?
Any suggestions or pointers will be most appreciated.
NilanHi Nilan,
You can see a simple example here.,on how to pass and receive XML elements as web service params.
http://otn.oracle.com/sample_code/tech/java/codesnippet/webservices/docservice/content.html
A tutorial on Using Web Services with Oracle9i Reports
http://otn.oracle.com/tech/webservices/htdocs/series/reports/content.html
Regards
Elango. -
How do I using Workshop's XMLMap Defined XML Document ?
Hi ,
I wonder that how can call the Workshop's XMLMap Defined Document in Java
Application Client.
I need to get not returned Object but returned XML Document in Java
Application Client.
Regards.Here's a more complete example:
* @jws:operation
public org.w3c.dom.Document getPurchaseOrderAsDocument() throws org.xml.sax.SAXException
Document doc = null;
try
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder db = fact.newDocumentBuilder();
doc = db.parse(new InputSource(new FileInputStream(new File("c:/temp/mypo.xml"))));
catch (IOException ioe)
throw new SAXException("IO exception occurred", ioe);
catch (ParserConfigurationException pce)
throw new SAXException("JAXP Parser configuration exception occurred", pce);
return doc;
HTH,
Mike Wooten
"dudwnrla" <[email protected]> wrote:
Hi ,
I wonder that how can call the Workshop's XMLMap Defined Document in
Java
Application Client.
I need to get not returned Object but returned XML Document in Java
Application Client.
Regards. -
How to parse XML document returned by webservices
Hi,
I have a form (version 10.1.2.0) which has to display the credit card types using webservices. I created the webstub and jar file through jdeveloper and then after adding the jar files in the respective classpaths, I import it in the forms. I write the code in when-button-pressed and it gives the result in xml document like this:
<?xml version="1.0" encoding="UTF-8"?><WSAnswerTO><error>false</error><errorMessage></errorMessage><
results><CardTypeTO><carTypId>3</carTypId><type>AMERICAN
EXPRESS</type><numLength>15</numLength><cvvLength>4</cvvLength><comments>1 800-639-0002</comments></CardTypeTO><CardTypeTO><carTypId>4</carTypId><type>DISCOVER</type><numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-347-2683</comments></CardTypeTO><CardTypeTO><carTypId>1</carTypId><type>MASTERCARD</type><numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-633-7367</comments></CardTypeTO><CardTypeTO><carTypId>2</carTypId><type>VISA</type><numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-945-2000</comments></CardTypeTO></results></WSAnswerTO>
From the above xml document, I only need to display the type (such as AMERICAN EXPRESS, VISA, ETC) in my forms. Can somebody please tell me how to do it. Do I need to store the values in a table first and then retrieve it. Please advise. I have already read a otn document in xml parsing but I didnt understand anything from it.
Please help. Thanks in advance.Hello,
It probably exists a database package/function to parse this kind of stuff.
If you want to keep the process into the Forms, here is a PL/SQL package you can use:
CREATE OR REPLACE PACKAGE Pkg_Tools AS
-- Types --
-- table of strings --
TYPE TYP_TAB_CHAR IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER;
-- Methodes --
-- function that return all contents for a given XML tag --
FUNCTION Get_Xml_Tag
PC$XmlContent IN VARCHAR2, -- XML string
PC$Tag IN VARCHAR2, -- searched tag
PC$NewLine IN VARCHAR2 DEFAULT CHR(10) -- defaull NL character
RETURN TYP_TAB_CHAR ;
END Pkg_Tools;
CREATE OR REPLACE PACKAGE BODY Pkg_Tools
IS
-- fonction de retour du contenu d'une balise XML --
FUNCTION Get_Xml_Tag
PC$XmlContent IN VARCHAR2, -- contenu XML
PC$Tag IN VARCHAR2, -- tag recherche
PC$NewLine IN VARCHAR2 DEFAULT CHR(10) -- defaull NL character
RETURN TYP_TAB_CHAR
IS
TC$Table TYP_TAB_CHAR ;
LC$Ligne VARCHAR2(32000) ;
LC$Xml VARCHAR2(32000) ;
LN$INDEX PLS_INTEGER := 0 ;
LN$TagDeb PLS_INTEGER ;
LN$TagFin PLS_INTEGER ;
LN$TagLength PLS_INTEGER ;
LN$LigLength PLS_INTEGER ;
LN$Occur PLS_INTEGER := 1 ;
BEGIN
IF ( PC$XmlContent IS NOT NULL AND PC$Tag IS NOT NULL ) THEN
LC$Xml := REPLACE( PC$XmlContent, CHR(13), '' ) ;
LN$TagLength := LENGTH( PC$Tag ) ;
LOOP
LN$TagDeb := INSTR( LC$Xml, PC$Tag, 1, LN$Occur ) ;
LN$TagFin := INSTR( LC$Xml, '</' || SUBSTR(PC$Tag,2, 256), 1, LN$Occur ) ;
LN$LigLength := (LN$TagFin - ( LN$TagDeb + LN$TagLength ) ) ;
IF (LN$TagDeb > 0 AND LN$TagFin > 0 ) THEN
LN$Occur := LN$Occur + 1 ;
LC$Ligne := SUBSTR( LC$Xml, LN$TagDeb + LN$TagLength, LN$LigLength ) ;
LOOP
LN$INDEX := LN$INDEX + 1 ;
LN$TagDeb := INSTR( LC$Ligne, PC$NewLine ) ;
IF LN$TagDeb > 0 THEN
IF Trim( SUBSTR( LC$Ligne, 1, LN$TagDeb - 1 )) IS NOT NULL THEN
TC$Table(LN$INDEX) := SUBSTR( LC$Ligne, 1, LN$TagDeb - 1 ) ;
ELSE
LN$INDEX := LN$INDEX - 1 ;
END IF ;
LC$Ligne := SUBSTR( LC$Ligne, LN$Tagdeb + LENGTH( PC$NewLine ), 30000 ) ;
ELSE
IF Trim(LC$Ligne) IS NOT NULL THEN
TC$Table(LN$INDEX) := LC$Ligne ;
END IF ;
EXIT ;
END IF ;
END LOOP ;
ELSE
EXIT ;
END IF ;
END LOOP ;
END IF ;
RETURN TC$Table ;
END Get_Xml_Tag ;
END Pkg_Tools;
/Then the call:
DECLARE
LC$t VARCHAR2(2000);
LT$Table Pkg_Tools.TYP_TAB_CHAR ;
BEGIN
lc$t := '<?xml version="1.0" encoding="UTF-8"?><WSAnswerTO><error>false</error><errorMessage></errorMessage><results>'
||'<CardTypeTO><carTypId>3</carTypId><TYPE>AMERICAN EXPRESS</TYPE><numLength>15</numLength><cvvLength>4</cvvLength>'
||'<comments>1 800-639-0002</comments></CardTypeTO><CardTypeTO><carTypId>4</carTypId><TYPE>DISCOVER</TYPE>'
||'<numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-347-2683</comments></CardTypeTO>'
||'<CardTypeTO><carTypId>1</carTypId><TYPE>MASTERCARD</TYPE><numLength>16</numLength><cvvLength>3</cvvLength>'
||'<comments>1 800-633-7367</comments></CardTypeTO><CardTypeTO><carTypId>2</carTypId><TYPE>VISA</TYPE>'
||'<numLength>16</numLength><cvvLength>3</cvvLength><comments>1 800-945-2000</comments></CardTypeTO></results></WSAnswerTO>' ;
LT$Table := Pkg_Tools.Get_Xml_Tag(LC$T,'<TYPE>') ;
IF LT$Table.COUNT > 0 THEN
FOR i IN LT$Table.First .. LT$Table.Last LOOP
dbms_output.put_line( 'Table(' || i || ')=' || LT$Table(i) ) ;
END LOOP ;
ELSE
dbms_output.put_line( 'tag xml not found' ) ;
END IF ;
END;Francois -
Carriage Returns & Line Feeds in XML documents
Does anyone know why the PL/SQL XML parser will NOT work with Carriage Returns (0x0D) within the XML document?
Currently I'm having to strip them out, leaving just the Line Feed (0x0A).
I only realised this after looking at the family.xml example document.
T.I.A.
GeoffI forgot to mention that I'm running Oracle 8i on Windows NT.
-
My Task is To Parse a XML Document to Return CLOB's
Hi folks
I am writing this mail in the hope of getting a help.Please
give me a shoulder to keep me going.
The task is to parse a XML document for a specific Tag and
read the Tag content in CLOB to return CLOB.
I know that the writetoclob will do the job as
per oracle documentation.
I am giving the code where i got stuck.
Please help me complete my rest of coding.
Thanks
Input variables are
XMLin in CLOB, -- Incoming XML Document Structure
Partype in varchar2, -- Tagname
Result out CLOB -- Return Tag value CLOB data type.
My Code : -
Declare
p xmlparser.parser;
d xmldom.DOMDocument;
e xmldom.DOMElement;
nl xmldom.DOMNodeList;
n xmldom.DOMNode;
tagvalue varchar2(255);
paramsIn Clob;
result CLOB;
BEGIN
--loading SecXML
dbms_lob.createtemporary(paramsIn,true);
dbms_lob.append(paramsIn,XMLin);
--dbms_output.put_line('ParsebyTag ='||Partype);
--defining parser
p := xmlparser.newparser;
xmlparser.parseClob(p,paramsIn);
d := xmlparser.getDocument(p);
--get tagvalue
nl := xmldom.getElementsByTagName(d,partype);
n := xmldom.item(nl,0);
IF xmldom.getlength (nl) > 0
THEN
n := xmldom.item (nl, 0);
=>=>=> => xmldom.writetoclob (n, result); <=<=<=<=<=<=====
END IF;
return; -- from a procedure
The above line marked with a arrow does not work for CLOB Variables.
Please explain with a corrected code to complete this task.
Thanks for reading my request.
Please reply to this message poster as i am frequently
checking this to see a answer.
my email is [email protected]
Balaji.First, you have 2 variables with the same name,
Second, let me show you what is that you need to do:
PROCEDURE WriteDataToClob(XMLin in CLOB, Partype in varchar2, Result out CLOB) IS
Declare
p xmlparser.parser;
d xmldom.DOMDocument;
e xmldom.DOMElement;
nl xmldom.DOMNodeList;
n xmldom.DOMNode;
tagvalue varchar2(255);
TempClob Clob;
BEGIN
--Create a temporary clob
dbms_lob.createtemporary(TempClob,true);
--loading SecXML
--defining parser
p := xmlparser.newparser;
xmlparser.parseClob(p,XMLin);
d := xmlparser.getDocument(p);
--get tagvalue
nl := xmldom.getElementsByTagName(d,partype);
n := xmldom.item(nl,0);
IF xmldom.getlength (nl) > 0 THEN
n := xmldom.item (nl, 0);
xmldom.writetoclob (n, TempClob );
END IF;
Result := TempClob;
dbms_lob.FreeTemporary(TempClob);
END; -
Parsing the return value from a http request into a xml document?
suppose a url "http;//abc.com/index.asp" that return a string like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <bbsend>
<title>xml testing</title>
- <record>
<sender>111111</sender>
<date>2004-01-05 04:11:44</date>
<message>yes!</message>
</record>
- <record>
<sender>22222222</sender>
<date>2004-01-14 01:06:31</date>
<message>A</message>
</record>
</bbsend>
how can i parsing this return value into a xml document???
i try something like this:
URL url = new URL("http://abc.com/index.asp");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
DataInputStream in = new DataInputStream(http.getInputStream());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(in);
System.out.println(document.getNodeValue());
But fail , can anyone helpdo u mean get the xml content??
i am doing a project with BBSend
[email protected] -
How to check empty return from Get XML Document Data?
If Get XML Document Data doesn't return a result, how do you test it? String.isEmpty() doesn't do the trick, it still throws the exception "java.lang.NullPointerException". I can't seem to be able to match that up to a cisco exception with a "On Exception Goto" step (which I put right before the XML Document Data step). Any clues anyone?
Hi,
Try this:
variable=Get XML Document Data ()
if(variable == null) then
true
false
Gabriel. -
UCCX XPath on Get XML Document Data Step always returns null
Hello,
Can someone tell whats wrong with my XPath, because it always returns null. I have tried different variations and nothing. I'm using UCCX 7.0
XML
<?xml version="1.0" encoding="utf-8" ?>
<GetManagersResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.labdomain.com/">
<ClaimManagersList>
<X_CLAIM_MANAGER>
<ClaimManagerUserName>test</ClaimManagerUserName>
</X_CLAIM_MANAGER>
</ClaimManagersList>
</GetManagersResult>
XPATH
"/descendant::GetManagersResult/child::ClaimManagersList/child::X_CLAIM_MANAGER/child::ClaimManagerUserName"
During debug, this is the value of the xml document when it reaches the Get XML Document Data step:
TEXT[<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<GetManagersResult xmlns=\"http://www.labdomain.com/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <ClaimManagersList>\r\n <X_CLAIM_MANAGER>\r\n <ClaimManagerUserName>test</ClaimManagerUserName>\r\n </X_CLAIM_MANAGER>\r\n </ClaimManagersList>\r\n</GetManagersResult>]It's your XML namespace in the root element.
First off, I have never seen the CRS Editor play nice when XML namespaces are involved.
Secondly, with your namespace in place, not even a generic xpath expression tester can find your data. See attachements.
I think that if you find a way to either: not send, or remove the namespace from your document, your xpath expression will work.
With Namespaces
Without Namespaces -
Get XML Document Data step always returns NULL
Hi All,
I was hoping someone might be able to help with this.
I'm writing a holiday script, it uses XML to check whether the date is a holiday or halfday. XML below
<?xml version="1.0" encoding="ISO-8859-1"?>
<Holidays>
<Holiday Date="1/1/2012">Holiday</Holiday>
<Holiday Date="3/1/2012">Halfday</Holiday>
<Holiday Date="6/1/2012">Holiday</Holiday>
<Holiday Date="5/4/2012">Halfday</Holiday>
<Holiday Date="6/4/2012">Holiday</Holiday>
<Holiday Date="8/4/2012">Holiday</Holiday>
<Holiday Date="9/4/2012">Holiday</Holiday>
<Holiday Date="30/4/2012">Halfday</Holiday>
<Holiday Date="1/5/2012">Holiday</Holiday>
<Holiday Date="17/5/2012">Holiday</Holiday>
<Holiday Date="27/5/2012">Holiday</Holiday>
<Holiday Date="6/6/2012">Holiday</Holiday>
<Holiday Date="23/6/2012">Holiday</Holiday>
<Holiday Date="6/4/2012">Holiday</Holiday>
<Holiday Date="3/11/2012">Halfday</Holiday>
<Holiday Date="25/12/2012">Holiday</Holiday>
<Holiday Date="26/12/2012">Holiday</Holiday>
<Holiday Date="19/10/2012">Halfday</Holiday>
</Holidays>
However when I debug the script the result of the Get XML Document step always returns null.
Xpath work great in notepad++
My code is attached, anyone with any pointers?
Regards,
AndyYour XPATH of:
"/Holidays/Holiday[@Date='+DateString+']"
Needs to be:
"/Holidays/Holiday[@Date='"+DateString+"']"
Good luck and happy scripting!
Anthony Holloway
Please use the star ratings to help drive great content to the top of searches. -
Error while loading an XML document using a structured application
Hi,
I try to load an XML document using a structured application defined in the default structapps.fm
My code is shown down, extracted from the FDK API code sample.
Problem, I always have the same message :
"Cannot find the file named e:\xml\AdobeFrameMaker10\file. Make sure that the file exists. "
Where "e:\xml\AdobeFrameMaker10\" is my install directory.
So I assume that frame try to find the structapps.fm file but does not find it.
What else can it be ?
Does anyone knowns how to achieve this simple task using extendScript ?
Thanks for any comments, Pierre
function openXMLFile(myLastFile) {
var filename = myLastFile.openDlg("Choose XML file ...", "*.xml", false);
if (filename != null) {
/* Get default open properties. Return if it can’t be allocated. */
var params = GetOpenDefaultParams();
/* Set properties to open an XML document*/
/*Specify XML as file type to open*/
var i = GetPropIndex(params, Constants.FS_OpenAsType)
params[i].propVal.ival = Constants.FV_TYPE_XML;
/* Specify the XML application to be used when opening the document.*/
i = GetPropIndex(params, Constants.FS_StructuredOpenApplication)
params[i].propVal.sval = "myApp";
i = GetPropIndex(params, Constants.FS_FileIsOldVersion)
params[i].propVal.ival = Constants.FV_DoOK
i = GetPropIndex(params, Constants.FS_FontNotFoundInDoc)
params[i].propVal.ival = Constants.FV_DoOK
i = GetPropIndex(params, Constants.FS_FileIsInUse)
params[i].propVal.ival = Constants.FV_DoCancel
i = GetPropIndex(params, Constants.FS_AlertUserAboutFailure)
params[i].propVal.ival = Constants.FV_DoCancel
/*The structapps.fm file containing the specified application must have
already been read. The default structapps.fm file is read when FrameMaker is
opened so this shouldn't be a problem if the application to be used is
listed in the structapps.fm file.*/
var retParm = new PropVals()
var fileObj = Open(filename, params, retParm);
return fileObj
} else {
return null;Pierre,
Depending on the object "myLastFile", the method openDlg might not even exist (if the myLastFile object is not a File object, for instance). And I do not see any need for the myLastFile anyhow, as you are presenting a dialog to select a file to open. I recommend using the global ChooseFile( ) method instead. This will give you a filename as string in full path notation, or null when no file was selected in the dialog. I am not sure what your ExtendScript documentation states about the return value for ChooseFile, but if that differs from what I am telling you here, the documentation is wrong. So, if you replace the first lines of your code with the following it should work:
function openXMLFile ( ) {
var filename = ChooseFile ( "Choose XML file ...", "", "*.xml", Constants.FV_ChooseSelect );
While writing this, I see that Russ has already given you the same advice. Use the symbolic constant value I indicated to use the ChooseFile dialog to select a single file (it can also be used to select a directory or open a file - but you want to control the opening process yourself). Note that this method allows you to set a start directory for the dialog (second parameter). The ESTK autocompletion also gives you a fifth parameter "helplink" which is undocumented and can safely be ignored.
Good luck
Jang -
Problem replacing Null nodes with real values in XML documents...
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
Our friends in Java land are insisting on passing data between Java and PL/SQL using fairly small XML documents (don't ask). I then need to extract the input parameter values and pass them, on to the stored procedures that actually do the work. These return a result which needs to be returned to the java layer in the output XML document.
Here is a cut down version of the input XML...
<ParameterList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameter>
<Id>1</Id>
<Result xsi:nil="true"/>
</Parameter>
<Parameter>
<Id>2</Id>
<Result xsi:nil="true"/>
</Parameter>
</ParameterList>
and this is an example of what I am expected to return...
<ParameterList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameter>
<Id>1</Id>
*<Result>SUCCESS</Result>*
</Parameter>
<Parameter>
<Id>2</Id>
*<Result>WARNING</Result>*
</Parameter>
</ParameterList>
i.e. I am expected to replace the value of the Result node with a string indicating the succes or otherwise of the underlying PL/SQL process.
I am extracting the input values using the DBMS_XMLDOM functions and naively assumed that DBMS_XMLDOM.SETNODEVALUE could be used to update the value in the Result node - It didn't work so I resorted to reading the documentation which revealed that it will not work for a null node.
Am I going to have to use XSLT to generate the output XML from the Input and incorprate the result? Or is there a simpler way?
I have used XSLT in Oracle before and still have the nervous tick...Thanks A Non,
With your suggestion and a bit of help from the w3schools.com xml dom tutorial I eventually managed to work out how to do this.
Here is the code (with all my debug stuff in so it looks worse than it is...)
create or replace
PROCEDURE ExtractXMLValues (p_inXml IN CLOB ) IS
l_string VARCHAR2(4000);
l_value VARCHAR2(4000);
l_DOM_doc dbms_xmldom.DOMDocument;
l_DOM_node dbms_xmldom.DOMNode;
l_new_DOM_node dbms_xmldom.DOMNode;
l_new_element dbms_xmldom.DOMElement;
l_new_DOM_nodevalue dbms_xmldom.DOMNode;
l_value_Node dbms_xmldom.DOMNode;
l_parameter_Node dbms_xmldom.DOMNode;
--l_DOM_nodelist dbms_xmldom.DOMNodeList;
l_Result_DOM_node dbms_xmldom.DOMNode;
BEGIN
l_DOM_doc := dbms_xmldom.newDomDocument(p_inXml);
l_DOM_node := dbms_xmldom.makeNode(l_DOM_doc);
dbms_xmldom.writeToBuffer(l_DOM_node, l_string);
dbms_output.put_line('1 ' || l_string);
l_parameter_node := dbms_xslprocessor.selectSingleNode(l_DOM_node,'//Parameter');
-- get the current values in the XML document for Id and Result
l_Result_DOM_node := dbms_xslprocessor.selectSingleNode(l_DOM_node,'//Id');
l_value_Node := dbms_xmldom.getFirstChild(l_Result_DOM_node);
l_value := dbms_xmldom.getnodevalue(l_value_Node);
dbms_xmldom.writeToBuffer(l_Result_DOM_node, l_string);
dbms_output.put_line('2 ' || l_string || ' : ' || l_value);
l_Result_DOM_node := dbms_xslprocessor.selectSingleNode(l_DOM_node,'//Result');
l_value_Node := dbms_xmldom.getFirstChild(l_Result_DOM_node);
l_value := dbms_xmldom.getnodevalue(l_value_Node);
dbms_xmldom.writeToBuffer(l_Result_DOM_node, l_string);
dbms_output.put_line('3 ' || l_string || ' : ' || l_value);
-- create new Result node
l_new_DOM_node := dbms_xmldom.makenode(dbms_xmldom.createElement(l_DOM_doc, 'Result'));
dbms_xmldom.writeToBuffer(l_new_DOM_node, l_string);
dbms_output.put_line('4 New node : ' || l_string);
-- create a value for it
l_new_DOM_nodevalue := dbms_xmldom.makenode(dbms_xmldom.createtextnode(l_DOM_doc, 'SUCCESS'));
dbms_xmldom.writeToBuffer(l_new_DOM_nodevalue, l_string);
dbms_output.put_line('5 New node value : ' || l_string);
-- add the value to the new Result node
l_new_DOM_nodevalue := dbms_xmldom.appendchild(l_new_DOM_node, l_new_DOM_nodevalue);
dbms_xmldom.writeToBuffer(l_new_DOM_node, l_string);
dbms_output.put_line('6 New node : ' || l_string);
-- replace the old node with the new one
l_Result_DOM_node := dbms_xmldom.replaceChild(l_parameter_node, l_new_DOM_node, l_Result_DOM_node);
dbms_xmldom.writeToBuffer(l_parameter_node, l_string);
dbms_output.put_line('6 parameter node : ' || l_string);
dbms_xmldom.writeToBuffer(l_DOM_node, l_string);
dbms_output.put_line('7 Updated document ' || l_string);
dbms_xmldom.freeDocument(l_DOM_doc);
END ExtractXMLValues;
and the output...
1 <ParameterList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameter>
<Id>1</Id>
<Result xsi:nil="true"/>
</Parameter>
</ParameterList>
2 <Id>1</Id> : 1
3 <Result xsi:nil="true"/> :
4 New node : <Result/>
5 New node value : SUCCESS
6 New node : <Result>SUCCESS</Result>
6 parameter node : <Parameter>
<Id>1</Id>
<Result>SUCCESS</Result>
</Parameter>
7 Updated document <ParameterList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Parameter>
<Id>1</Id>
*<Result>SUCCESS</Result>*
</Parameter>
</ParameterList>
One question, why do the dbms_xmldom functions return the Old value? I was expecting the returned value to be the updated node.
Edited by: Lone voice on May 14, 2009 11:24 AM -
I have extracted some code from codeproject to
reindent an XML document. Does anyone know how I can modify the stylesheet to make it so that the transform of an XML file will result in empty tags showing up as <tag /> instead of <tag></tag>?
// http://www.codeproject.com/Articles/43309/How-to-create-a-simple-XML-file-using-MSXML-in-C
MSXML2::IXMLDOMDocumentPtr FormatDOMDocument(MSXML2::IXMLDOMDocumentPtr pDoc)
LPCSTR const static szStyleSheet =
R"!(<?xml version="1.0" encoding="utf-8"?>)!"
R"!(<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">)!"
R"!( <xsl:output method="xml" indent="yes"/>)!"
R"!( <xsl:template match="@* | node()">)!"
R"!( <xsl:copy>)!"
R"!( <xsl:apply-templates select="@* | node()"/>)!"
R"!( </xsl:copy>)!"
R"!( </xsl:template>)!"
R"!(</xsl:stylesheet>)!";
MSXML2::IXMLDOMDocumentPtr pXmlStyleSheet;
pXmlStyleSheet.CreateInstance(__uuidof(MSXML2::DOMDocument60));
pXmlStyleSheet->loadXML(szStyleSheet);
MSXML2::IXMLDOMDocumentPtr pXmlFormattedDoc;
pXmlFormattedDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
CComPtr<IDispatch> pDispatch;
HRESULT hr = pXmlFormattedDoc->QueryInterface(IID_IDispatch, (void**)&pDispatch);
if (SUCCEEDED(hr))
_variant_t vtOutObject;
vtOutObject.vt = VT_DISPATCH;
vtOutObject.pdispVal = pDispatch;
vtOutObject.pdispVal->AddRef();
hr = pDoc->transformNodeToObject(pXmlStyleSheet, vtOutObject);
//By default it is writing the encoding = UTF-16. Let us change the encoding to UTF-8
// <?xml version="1.0" encoding="UTF-8"?>
MSXML2::IXMLDOMNodePtr pXMLFirstChild = pXmlFormattedDoc->GetfirstChild();
// A map of the a attributes (vesrsion, encoding) values (1.0, UTF-8) pair
MSXML2::IXMLDOMNamedNodeMapPtr pXMLAttributeMap = pXMLFirstChild->Getattributes();
MSXML2::IXMLDOMNodePtr pXMLEncodNode = pXMLAttributeMap->getNamedItem(_T("encoding"));
pXMLEncodNode->PutnodeValue(_T("UTF-8")); //encoding = UTF-8
return pXmlFormattedDoc;
Or, if there is some other method for reindenting a MSXML2::IXMLDOMDocumentPtr object where I can specify how I want empty tags to be stored, that would be great too. However, I don't want it to lose its status of an MSXML2::IXMLDOMDocumentPtr object.
I.e. I would like to still perform operations on the result as if it was still an MSXML2::IXMLDOMDocumentPtr object.
Thanks,
A
AdrianIf anyone is interested, I got an answer on StackOverflow
here.
Adrian -
Heap space error while creating XML document from Resultset
I am getting Heap space error while creating XML document from Resultset.
It was working fine from small result set object but when the size of resultset was more than 25,000, heap space error
I am already using -Xms32m -Xmx1024m
Is there a way to directly write to xml file from resultset instead of creating the whole document first and then writing it to file? Code examples please?
here is my code:
stmt = conn.prepareStatement(sql);
result = stmt.executeQuery();
result.setFetchSize(999);
Document doc = JDBCUtil.toDocument(result, Application.BANK_ID, interfaceType, Application.VERSION);
JDBCUtil.write(doc, fileName);
public static Document toDocument(ResultSet rs, String bankId, String interfaceFileType, String version)
throws ParserConfigurationException, SQLException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element results = doc.createElement("sims");
results.setAttribute("bank", bankId);
results.setAttribute("record_type", "HEADER");
results.setAttribute("file_type", interfaceFileType);
results.setAttribute("version", version);
doc.appendChild(results);
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
String columnName="";
Object value;
while (rs.next()) {
Element row = doc.createElement("rec");
results.appendChild(row);
for (int i = 1; i <= colCount; i++) {
columnName = rsmd.getColumnLabel(i);
value = rs.getObject(i);
Element node = doc.createElement(columnName);
if(value != null)
node.appendChild(doc.createTextNode(value.toString()));
else
node.appendChild(doc.createTextNode(""));
row.appendChild(node);
return doc;
public static void write(Document document, String filename) {
//long start = System.currentTimeMillis();
// lets write to a file
OutputFormat format = new OutputFormat(document); // Serialize DOM
format.setIndent(2);
format.setLineSeparator(System.getProperty("line.separator"));
format.setLineWidth(80);
try {
FileWriter writer = new FileWriter(filename);
BufferedWriter buf = new BufferedWriter(writer);
XMLSerializer FileSerial = new XMLSerializer(writer, format);
FileSerial.asDOMSerializer(); // As a DOM Serializer
FileSerial.serialize(document);
writer.close();
} catch (IOException ioe) {
ioe.printStackTrace();
//long end = System.currentTimeMillis();
//System.err.println("W3C File write time :" + (end - start) + " " + filename);
}you can increase your heap size..... try setting this as your environment variable.....
variable: JAVA_OPTS
value: -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m
Maybe you are looking for
-
How does IITTrackCollection handle ItemByName if there are multiple tracks by the same name?
I am writing a program in C# that is trying to check if a track already exists in the iTunes Library before adding it (thus preventing duplicates). The best method I have come up to do this with is to use 'MyPlaylist.ItemByName(SongName)' to retriev
-
Mail - Forwarding attachments manually and with rules - how do I keep my attachments?
I have the latest updates of Lion on by MacBookPro (late 2010 model). I use mail to receive mail from my business account (Exchange account) and my personal account (IMAP account). Up until this summer, everything was working peachy with the system.
-
Using Excel 2007 to display and auto-refresh planning.
Hi all, a customer wants to display a simple planning screen on a 24" monitor. We're using an old domain pc, with domain user (planning) logged on to display the planning file. We've configured the worksheet so that multiple users can edit it. I've a
-
Changing file multiple file names and extensions
hi all i have just converted a couple of files with some software, but it hasnt put the file extension on, does anyone know of a way to automatically change them, they are already mp4 files but missing the .mp4 on the name part, can anyone help me ou
-
Find edit timing of clips with offline media?
Adobe Premiere Pro CS3 version 3.2.0 (374) I was working on a project when one day the source video files were not supported. The program would be unable to find the source file and ask where it was. When I selected it, a "File Import Failure" dialog