Passing / parsing XML String IN / OUT from PL / SQL package
Hello, People !
I am wondering where can I find exact info (with code sample) about following :
We use Oracle 8.1.6 and 8.1.7. I need to pass an XML String (could be from VARCHAR2 to CLOB) from VB 6.0 to PL/SQL package. Then I need to use built in PL/SQL XML parser to parse given string (could be large hierarchy of nodes)
and the return some kind of cursor thru I can loop and insert data into
different db Tables. (The return value may have complex parent/child data relationship - so I am not sure If this should be a cursor)
I looked online many site for related info - can't find what I am looking
for - seems like should be a common question.
Thanx a lot !
Hello, People !
I am wondering where can I find exact info (with code sample) about following :
We use Oracle 8.1.6 and 8.1.7. I need to pass an XML String (could be from VARCHAR2 to CLOB) from VB 6.0 to PL/SQL package. Then I need to use built in PL/SQL XML parser to parse given string (could be large hierarchy of nodes)
and the return some kind of cursor thru I can loop and insert data into
different db Tables. (The return value may have complex parent/child data relationship - so I am not sure If this should be a cursor)
I looked online many site for related info - can't find what I am looking
for - seems like should be a common question.
Thanx a lot !
Similar Messages
-
HI
I have 2 IPads, I am unable to use one of it because I have forgotten my pass code and also logged out from iCloud accidentially. Can you please help me to solve this problem.
Cheers
RaveenaFollow the instructions on this page : Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support
-
while designind an mvc architecutre in php I found display
data on site was slow so I generate a xml sheet an used spry Data
loading was fast an dproduced and I also performed many operations
like sorting ,galeery making ..etc... but main thing is that I can
not parse a xml string using spry only a xml file can be parsed
my application required to parse xml stringI'm not sure if this is valid in your situation, but OC4J comes with Oracle XMLParser.
Simply use the JAXP API to parse/build/modify XML and the Oracle XMLParser implementation will be used behind the scenes.
If you must use xerces/xalan, try putting the jars in OC4J_HOME/j2ee/home/lib instead.
HTH //Anders -
Invoking Web Service From PL SQL package
Below is the sample code to invoke web service from pl/sql package using UTL_HTTP:
Declare
http_req UTL_HTTP.req;
http_resp UTL_HTTP.resp;
Begin
http_req :=
UTL_HTTP.begin_request
'http://'
|| lv_hosturl
-- || '.net/soa-infra/services/finance_rt/Payments/paymentsprocess_client_ep',
--new url
|| '.net/soa-infra/services/finance_rt/PaymentsReq/paymentsprocess_client_ep?WSDL',
'POST',
'HTTP/1.1'
UTL_HTTP.set_header (http_req, 'Content-Type', 'text/xml');
-- since we are dealing with plain text in XML documents
UTL_HTTP.set_header (http_req,
'Content-Length',
LENGTH (lv_soap_request)
UTL_HTTP.set_header (http_req, 'SOAPAction', '');
-- required to specify this is a SOAP communication
UTL_HTTP.write_text (http_req, lv_soap_request);
http_resp := UTL_HTTP.get_response (http_req);
UTL_HTTP.read_text (http_resp, lv_soap_respond);
UTL_HTTP.end_response (http_resp);
resp := XMLTYPE.createxml (lv_soap_respond);
End;Hi,
there are a lot of option to make plsql web services .
First you can stay with jdev 10.1.3
Use the xmldb servlets
use jdev 11g tp4 to create plsql ws and upgrade to jdev 11g production
And I think in the next release of jdev it will be back , there are more options which disappeared like the adf bc sdo ws or jmx datacontrol etc.
thanks Edwin -
Problem in generate Java from PL SQL package in Jdeveloper
Hi
i have problem in create java class from PL SQL package in JDeveloper.
I use Database navigator of jdeveloper and right click on a package and choose Generate Java then in Jpublisher window choose my view Controller and accept other default values.
I call methods of generated class in the Action of a button in my JSP page, but when I click the button it throw null pointer exception !!! i fund one of generated method return null and it lead to this exception.
protected DefaultContext __tx = null;
public DefaultContext getConnectionContext() throws SQLException {
if (__tx==null){
__tx = (getConnection()==null) ? DefaultContext.getDefaultContext() : new DefaultContext(getConnection());
return __tx;
public Connection getConnection() throws SQLException
if (__onn!=null) return __onn;
else if (__tx!=null) return __tx.getConnection();
else if (__dataSource!=null) __onn= __dataSource.getConnection();
return __onn;
i try to generate class in Model project and create DataControl for that and use method action but noting change and i get null pointer again!!
Jdeveloper Versino = 11.1.1.7.0Let me ask you another question: Why do you generate java from the package at all?
Where do you want to call the package?
Back to your question: you should see code like
public void setDataSourceLocation(String dataSourceLocation) throws SQLException {
javax.sql.DataSource dataSource;
try {
Class cls = Class.forName("javax.naming.InitialContext");
Object ctx = cls.newInstance();
java.lang.reflect.Method meth = cls.getMethod("lookup", new Class[] { String.class });
dataSource = (javax.sql.DataSource) meth.invoke(ctx, new Object[] { "java:comp/env/" + dataSourceLocation });
setDataSource(dataSource);
} catch (Exception e) {
throw new java.sql.SQLException("Error initializing DataSource at " + dataSourceLocation + ": " + e.getMessage());
in the generated code. This code look up a datasource (which you have defined e.g. on the Weblogic Server) by calling the method
setDataSourceLocaltion("jdbc/HRConnDS");
This look up the datasource nad stores it in the class variable.
Timo -
Support for Creating Web Service from pl/sql package in JDeveloper 11
We have been creating all of our web services from pl/sql packages in our Oracle database using JDeveloper 10.1.3.1. I understand that this capability is not supported in Jdev 11. We have been mandated to either move up to JDeveloper 11, or consider switching to eclipse, or even VS2008 and run .NET services from IIS. I have seen work-around solutions using TopLink and Jdev 11. Are there plans to revive this feature in the near future? We're now looking at switching to .NET since we could scrap our OAS instances and use IIS to publish web services. The only reason we were sticking with Oracle was the ease in converting all our existing package to web services with Jdev.
Is anyone else in the same situation. If so, what solutions are you considering?Hi,
there are a lot of option to make plsql web services .
First you can stay with jdev 10.1.3
Use the xmldb servlets
use jdev 11g tp4 to create plsql ws and upgrade to jdev 11g production
And I think in the next release of jdev it will be back , there are more options which disappeared like the adf bc sdo ws or jmx datacontrol etc.
thanks Edwin -
Call a unix script from pl/sql package
Hi,
Using 11.2.0.3 on AIX.
Is it possible to call unix script from pl/sql package?
I am cretaing a file in a directory but would like this to automatically be written to an archive directory as well.
Could either use 2 utl_file.put_lines to 2 separate directories or 1 utl_file and cal script to archive file in another directory.?
Thoughts?
Thanksuser5716448 wrote:
What am I doing wrong?think how file name will look like:
SQL> select 'file_name' || to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
'FILE_NAME'||TO_CHAR(SYSDATE
file_name15/08/2012 11:47:51Will AIX swallow such name? Obviously not. And, unfortunately, UTL_FILE.FCOPY doesn't raise an error in such case. So use someting like:
UTL_FILE.FCOPY ('SOURCE_DIR',v_FILE_NAME,'DEST_DIR',v_file_name||to_char(sysdate,'DD_MM_YYYY_HH24_MI_SS'));SY. -
How to parse XML string fetched from the database
i want to parse the XML string which is fetched from the oracle database.
i have inserted the string in xml format in the database. The type of the field in which it is inserted is varchart2.
I am successfully getting it using jdbc, storing it in a String.
Now it is appended with xml version 1.0 and string is ready for parsing.
Now i am making following programming.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = Builder.parse(xmlString);
Element root = doc.getDocumentElement();
NodeList node = root.getElementsByTagName("product");
But i am getting IOException at the statement
Document doc = Builder.parse(xmlString);
there fore i request u to kindly help me in solving this error.
-regards
pujanDocumentBuilder does not have a method parse with xml string as aparameter. The string should be a xml document uri.
Convert xml string to StringReader.
parse(new InputSource(new StringReader(xmlString))); -
Hi
Can anyone help me I am trying to parse a xml file that is in a StringBuffer and not a file.
Any suggestions would be great.
Thanks ;>You can create a StringReader object from your StringBuffer. Once you have a StringReader object, you can create an InputSource object. Then, you can parse the InputSource with a DocumentBuilder object. I enclosed the code to illustrate. The method printXml is only used to check that the XML string is properly parsed and retrieved.
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class Parsing
public static void main(String[] args)
StringBuffer yourStringBuffer = new StringBuffer("<message>"
+"<header>This is the message's header</header>"
+ "<body>This is the message's body</body>"
+ "</message>");
try {
DocumentBuilderFactory docBuilderFactory = new org.apache.crimson.jaxp.DocumentBuilderFactoryImpl();
//throws ParserConfigurationException
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
StringReader strReader = new StringReader(yourStringBuffer.toString());
//throws SAXException, IOException, IllegalArgumentException
Document doc = docBuilder.parse(new InputSource(strReader));
System.out.println(printXml(doc)); //check if the XML can be retreived, i.e. it has been parsed successfully
catch(ParserConfigurationException ex) {
ex.printStackTrace();
catch(SAXException ex) {
ex.printStackTrace();
catch(IOException ex) {
ex.printStackTrace();
catch(IllegalArgumentException ex) {
ex.printStackTrace();
//Convenient method to print a Document object.
public static String printXml(Document xmlDoc)
StringBuffer xml = new StringBuffer("************ Xml Document *************");
print(xmlDoc,xml);
return xml.toString();
protected static void print(Node node, StringBuffer strXml)
int type;
String elementName;
Node childNode;
NamedNodeMap attrs;
Attr attrib;
NodeList childNodes;
strXml.append(System.getProperty("line.separator"));
if(node == null)
return;
type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE: {
print(((Document)node).getDocumentElement(),strXml); //recursive call to browse the tree
break;
case Node.ELEMENT_NODE: {
elementName = node.getNodeName();
strXml.append("<" + elementName);
attrs = node.getAttributes();
if(attrs == null)
strXml.append(">");
else {
for(int i = 0; i < attrs.getLength(); i++) {
attrib = (Attr) attrs.item(i);
strXml.append(" " + attrib.getName() + "=\"" + attrib.getValue() + "\"");
strXml.append(">");
childNodes = node.getChildNodes();
if(childNodes == null) return;
for (int i = 0; i < childNodes.getLength(); i++) {
childNode = childNodes.item(i);
if(childNode.getNodeType() == Node.TEXT_NODE)
strXml.append(childNode.getNodeValue());
else
print(childNode,strXml);
strXml.append(System.getProperty("line.separator"));
strXml.append("</" + elementName + ">");
}Hope this helps. -
Getting Error while creating Document object after parsing XML String
Hi All,
I have been trying to parse an XML string using the StringReader and InputSource interface but when I am trying to create Document Object using Parse() method getting error like
[Fatal Error] :2:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.
seorg.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Please find the code below which i have been experimenting with:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.*;
public class TestMain {
public static void main(String[] args) {
String file = "";
file = loadFileContent("C:\\Test.xml");
System.out.println("contents >> "+file);
parseQuickLinksFileContent(file);
public static void parseQuickLinksFileContent(String fileContents) {
PWMQuickLinksModelVO objPWMQuickLinksModelVO = new PWMQuickLinksModelVO();
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader objRd = new StringReader(fileContents);
InputSource objIs = new InputSource(objRd);
Document document = builder.parse(objIs); // HERE I am getting Error.
System.out.println(document.toString());
What is happening while I am using builder.parse() method ???
Thanks,
Rajendra.Getting following error
[Fatal Error] :2:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.
seorg.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed. -
JDOM: Parsing XML String, getting error
Hello,
I am new to this forum, so please forgive me
if this has already been asked before. I want to
parse an XML string. I know the JDOM parser works
great with a file, but apparently I have been
unsuccessful parsing an XML String. Below is how I
initialize the parser:
import java.io.*; //Import proper packages
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import java.util.*;
import java.lang.*;
public class XMLParser{
private Document doc = null;
public XMLParser(String xml){
doc = readDocument(xml);
private Document readDocument(String xml) {
try {
SAXBuilder builder = new SAXBuilder();
org.jdom.Document result = builder.build(new
StringReader(xml));
return result;
} catch(JDOMException e) {
e.printStackTrace();
} catch(NullPointerException e) {
e.printStackTrace();
return null;
} //readDocument
The following is the error I receive:
JDOM/xmlparser.java [81:1] cannot resolve symbol
symbol : method build (java.io.StringReader)
location: class org.jdom.input.SAXBuilder
org.jdom.Document result = builder.build(new
StringReader(filename));
--> Arrow pointing to builder.build
Please if someone can help me out. If JDOM does not
have this feature, then can someone please recommend a
parser that can parse an XML String.Thank you for your help, although it seems like it was JDom 9 beta. When I tried with JDOM 8 beta, everything worked fine even with the StringReader. So if anyone is having similar problems with JDom 9 then try with JDom 8.
-
Hi,-
I am trying to parse an XML string with xpath as follows but I am getting null for getresult.
I am getting java.xml.xpath.xpathexpressionexception at line where
getresult = xpathexpression.evaluate(isource); is executed.
What should I do after
xpathexpression = xPath.compile("a/b");in the below snippet?
Thanks
String xmlstring ="..."; // a valid XML string;
Xpath xpath = XPathFactory.newInstance().newPath();
xpathexpression = xPath.compile("a/b");
// I guess the following line is not correct
InputSource isource = new inputSource(new ByteArrayInputStream(xmlstring.getBytes())); right
getresult = xpathexpression.evaluate(isource);My xml string is like:
<a>
<b>
<result> valid some more tags here
</result>
</b>
<c> 10
</c>
</a>Edited by: geoman on Dec 8, 2008 2:30 PMI've never used the version of evaluate that takes an InputSource. The difficulty with using it is that it does not save the DOM object. Each expression you evaluate will have to create the DOM object, use it once and then throw it away. I've yet to write a program that only needs one answer from an XML document. Usually, I use XPath to locate somewhere in a document and then read "nearby" content, add new content nearby, delete content, or move content. I'd suggest you may want to parse the XML stream and save the DOM Document.
Second, all of the XPath expressions search from a "context node". I have not had good luck searching from the Document object, so I always get the root element first. I think the expression should work if you use the root as the context node. You will need one of the versions of evaluate that uses an Object as the parameter. -
How to parse xml string using JSTL
Suppose this is my string:-----
<books>
<book>
<title id=1>Book Title A</title>
<author>A. B. C.</author>
<price>17.95</price>
</book>
<book>
<title id=2>Book Title B</title>
<author>X. Y. Z.</author>
<price>24.99</price>
</book>
</books>
and I want to read title id = 1 then, how to parse it, I found tutorials regarding parsing simple xml document but how to parse attributes of a given XMLBut both of them either parse a file or data from an input source. I don't think they handle strings.An InputSource can be constructed with a Reader as input. One useful subclass of Reader is StringReader, so you'd use something likeDocument doc = documentBuilder.parse(new InputSource(new StringReader(myXMLString)));
-
Hi! I'm having problems parsing an xml string. I've done DOM and SAX parsing before. But both of them either parse a file or data from an input source. I don't think they handle strings. I also don't want to write the string into a file just so I can use DOM or SAX.
I'm looking for something where I could simply do:
Document doc = documentBuilder.parse( myXMLString );
So the heirarchy is automatically established for me. Then I could just do
Element elem = doc.getElement();
String name = elem.getTagName();
These aren't the only methods I would want to use. Again, my main problem is how to parse xml if it is stored in a string, not a file, nor comming from a stream.
thanks!But both of them either parse a file or data from an input source. I don't think they handle strings.An InputSource can be constructed with a Reader as input. One useful subclass of Reader is StringReader, so you'd use something likeDocument doc = documentBuilder.parse(new InputSource(new StringReader(myXMLString)));
-
Getting null value while parsing "XML String" with encoding WINDOWS-1252.
Hi,
when I am converting the Follwoing "xml string " to Document, I am getting the "null" as a document value.
String strXML = "<?xml version="1.0" encoding="WINDOWS-1252"?>
<category name="SearchByAttributes" value="Search By Attributes">
<item name="ORDER_LINE_ID" description="Application Search Attributes" >
<attribute name="Sequence" value="0001"/>
</item>
</category>"
My "xml string" has the encoding vaule: WINDOWS-1252.
I am using the following code to convert the "xml string" to Document. I am getting the Document values as a "null" while converting the above "string xml"
String strXML = //my above string xml.
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
docBuilder = docBuilderFactory.newDocumentBuilder();
doc = docBuilder.parse(new InputSource(new StringReader(strXML)));
System.out.println("doc value.."+doc)//I am getting null value for "doc".
Can anyone help me to resolve the issue.Thagelapally wrote:
I am coverting the below "XML string" to Document, once it is converted I am reading that Document,which have an "attribue" Element in.
String strXML = "<?xml version="1.0" encoding="WINDOWS-1252"?>
<category name="SearchByAttributes" value="Search By Attributes">
<item name="ORDER_LINE_ID" description="Application Search Attributes" >
<attribute name="Sequence" value="0001"/>
</item>
</category>" I am using the above code to read the Document. When run the code in "OC4J Server" and using Jdeveloper as an editor,I am able to perfectly read the "attribute" element in the document with out any problem.Println statement printing as I expected.
System.out.println("Element Name..."+listOfAtt.getNodeName());
//getting Element Name as...."attribute"(as expected)
System.out.println("Element Attibrute list....."+elementAtt);
//getting Element Attribute list as an...."oracle.xml.parser.v2.XMLAttrList@afe"But when run the same code(reading the same Document) in Tomcat and Eclipse,println satatement not printing as i expected.
System.out.println("Element Name..."+listOfAtt.getNodeName());
//getting Element Name as...."#text"(I am expecting output value "attribute" but it is printing "#text" which i don't know)
System.out.println("Element Attibrute list....."+elementAtt);
//getting Element Attribute list as an...."null"(I am expecting output value object reference but it is printing "null"
(without the rest of the code, i'm guessing that) most likely you are grabbing the first child node of the item element. however, you are not accounting for some text nodes that are most likely in that list, like the whitespace between the item element and the attribute element. please go read some tutorials on xml, there are thousands of them out there, and they will answer all you initial questions much more efficiently than posting each step to the forums.
Maybe you are looking for
-
"Procurement Wizard" window opens for a particular warehouse while saving Sales Order
Hello All, We have upgraded SAP B1 8.8 to SAP B1 9.0 My client is facing one of problem while saving Sales order using particular warehouse. Actually client is having 4 warehouses (A,B,C,D) in which if they use one particular warehouse "A" for saving
-
Customer Statement to be Send by Email
HI, I have config the Customer statement by means of correnpondence & it working fine. But I need to send it through email maintained in customer master when i run f.27 mails should be send automatically. For doing this do we need to do any config r
-
Installing 9i on a Windows 98 computer
Is 9i really running on Windows98? I just made the installation but found that "wfnvg.ocx", "mmdx32.ocx" and "oip.dll" could not be registered not even manually. Will my database work? Thank you!
-
Start workflow with BAPI / RFC
HI! I want to start a workflow in Business workflow by RFC. Are there any BAPI for this that i can use. ?
-
Saving data next time PDF form opens
Hello, I've been looking all over. Where is the command to disable the feature that allows the previously entered data to be saved? I have the form on our server and don't want users to see data from other users. Right now they can. Thank you.