How to parse a XML stream sent to servlet with PUT method
Hi,
I have to interface my servlet app with other apps communicating with XML.
This way, My servlet will receive a XML stream in the http request, parse it and send back a XML message.
What I've done is :
An html page to send a XML File with a put method :
<form enctype="multipart/form-data" method="PUT" action="http://localhost:8080/MyApp/servlet/TestUploadServlet">
<input type="file" size="20" name="FileToUpload" value="Select File">
<input type="submit" name="UploadFile" value="Upload">
<input type="reset" value="Reset">
</form>
A servlet TestUploadServlet with :
SAXParser parser = new SAXParser( );
Trace.traceLine( "SAXParser" );
parser.setContentHandler (this);
try {
parser.parse( new InputSource( requete.getInputStream() ) );
catch (SAXException e) {
Trace.traceLine( e.getMessage() );
catch (IOException e) {
Trace.traceLine( e.getMessage() );
and the methods startElement, stopElement and other to work with the elements detected by the parser (already used by other programs parsing local xml files).
And it doesn't work.
is the html code is a good way to send a file in the http Put method ?
is the parser.parse( new InputSource( requete.getInputStream() ) ); a good method to read the stream ?
please help.
I think the problemn comes from the method used to send the <XML> stream.
Using an html form doesn't seem to be a good method.
I tried several methods or examples found and none of them seems to work.
here is another example in the servlet side :
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
ServletOutputStream output = res.getOutputStream();
output.println("ContentType: " + req.getContentType() + "<BR>");
int content_length = req.getContentLength();
output.println("ContentLength: " + content_length + "<BR>");
if(content_length > 0) {
output.println("Content: ");
ServletInputStream input = req.getInputStream();
byte [] buffer = new byte[1024];
int nb;
while((nb=input.read(buffer))!= -1) {
output.write(buffer,0,nb);
Can somebody tell me how to write a java code sending a http request with the content of a file in the content of the request ?
Similar Messages
-
How to display an xml file using a servlet with the styles given in an XSL
Dear Developer...
i have xml and xsl files.
Now i want to display the html output produced by the xsl and xml using a servlet...give me any samplecode.... except for the "using XSLT" part. But that doesn't make sense anyway because XSLT doesn't display anything, it just transforms data.
-
I am a new learner to XML & JAVA,I dont't know how to parse the XML file using JAXP,Who can tell me,Who can write an Example?
thx
Best Regards.Using the SAXParser in JAXP the parsing of the XML file is event driven.
Instantiate the parser:
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
InputSource is = new InputSource(new FileReader(theXML));call the parse method:
parser.parse(is, this);The following events are fired as the parser works through the XML public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws org.xml.sax.SAXException
public void endElement(String namespaceURI, String localName, String qName) throws org.xml.sax.SAXException
characters(char[] ch, int start, int length)etc.
You write what you want within each of these sections to handle the structure of your data. Keep in mind SAX is useful only when you know the structure of your XML. -
How to parse thus XML data?
Hi,experts:
In below thread:
Receiving .Net dataset with deployed proxies
i asked how to create a external definition in IR base on above XML data.
Now,i have created a XSD file base on the XML data.And importing it into IR successfully.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Status">
<xs:complexType>
<xs:attribute name="Result" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
And now,the question is how to parse the XML data in diffgr:diffgram segment.It seems a MS-XML syntax.Can it be parsed by XI?
I tried,but the following error occurs:
com.sap.aii.utilxi.misc.api.BaseRuntimeException: RuntimeException in Message-Mapping transformation: Cannot produce target element /ns0:ZMT_SD_ORDER01_RESULT. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at com.sap.aii.mappingtool.tf3.AMappingProgram.startHi,
The above Exception seems to be because of mapping error.
Check your mapping for all the mandatory 1-1 mapping, also the 1-unbounded parent node mapping.
Once when you import the XSD and activate your External Definition if it does without any error then there is no problem with your External Definition.
If this error occurs only when you test your mapping then this is mapping error and not because of XSD.
Please check the parent node mapping like 1-unbounded.
Reward Points if useful
Regards
Ashmi. -
How quickly parse big XML file (60 MB) ???
How quickly parse big XML file (60 MB) ???
I assume you mean load it into XML DB ?. Fundamentally your document is about the upper limit for 9.2.x. I would strongly recommend trying to break it up into a set of smaller documents using a SAX parser before trying to load it into XML DB. In 10g it should be possible to load much bigger documents than this.
-
How to Parse the XML generated by Mapping LookUp - RFC API
Hi Friends,
I m using the link by Michal Krawczyk for Mapping Lookups - RFC API
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1b439
How to parse the XML created in the target node ?
Regards
PraveshHi,
Check the second half of my code in this blog,
/people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
It deals with webservice call's but almost the same for RFC.
Regards
Bhavesh -
How to parse nested xml file using dom
i want to parse nested xml file
please tell me how to parse nested xml
for eg.
<xml>
<row>
<name>Rahul<name>
<row><newXml>
<newXML>
<Row>
<code>12</code>
</Row>
<newXML>
<XML>
please tell how to parse this fileNormally if you have no idea about X, the first thing you should do is google "X tutorial". You will find plenty of them out there. And the advantage is, they are better written than whatever we spend two minutes throwing together here. Not to mention that it saves us the two minutes.
But if you have specific questions with your SAX parser when you get it going, then ask them here. Actually, ask them in the XML forum here, not this one. -
How to Create an XML document from XSQL servlet which follows a particular DTD struct
how to Create an XML document from XSQL servlet which follows a particular DTD structure.Could anyone send me a sample code for this.
You'll need to associate an XSLT transformation with your XSQL page that transforms the canonical result into your DTD-valid format.
For example, given an XSQL page like:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="rss.xsl" ?>
<xsql:query max-rows="3" connection="demo" xmlns:xsql="urn:oracle-xsql">
select title,id,description,url,to_char(timestamp,'Mon DD') timestamp
from site_entry
order by id desc
</xsql:query>and an "rss.xsl" stylesheet that looks like this:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" doctype-system="rss-0.91.dtd"/>
<xsl:template match="/">
<xsl:for-each select="ROWSET/ROW">
<rss version="0.91">
<channel>
<title>Do You XML?</title>
<link>http://xml.us.oracle.com</link>
<description>Oracle XML Website Demo</description>
<language>en-us</language>
<xsl:for-each select="ITEM">
<item>
<title><xsl:value-of select="TITLE"/></title>
<link><xsl:value-of select="URL"/></link>
<description><xsl:value-of select="DESCRIPTION"/></description>
</item>
</xsl:for-each>
</channel>
</rss>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>You produce DTD-valid output against the rss-0.91.dtd DTD that looks like:
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE rss SYSTEM "rss-0.91.dtd">
<rss version="0.91">
<channel>
<title>Do You XML?</title>
<link>http://xml.us.oracle.com</link>
<description>Oracle XML Website Demo</description>
<language>en-us</language>
</channel>
</rss>
<rss version="0.91">
<channel>
<title>Do You XML?</title>
<link>http://xml.us.oracle.com</link>
<description>Oracle XML Website Demo</description>
<language>en-us</language>
</channel>
</rss>
<rss version="0.91">
<channel>
<title>Do You XML?</title>
<link>http://xml.us.oracle.com</link>
<description>Oracle XML Website Demo</description>
<language>en-us</language>
</channel>
</rss> -
How to parse an XMl without using prefix in the namespace and elements?
Hi
The following is a sample of the xml that I need to parse.
Without the prefix in the namespace section I am getting an error but when i just put in the prefix it works fine. Any help here would be greatly appreciated.
I think i need to change something in the parser set up...may be the somewhere in the bolded lines....but i am clueless...
//Xml begins
<?xml version="1.0" encoding="utf-8" ?>
- <Statemessages xsi:schemaLocation="http://www.SomeLocation.com/SomeXSD.xsd" xmlns="http://www.abcd.com/BSN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <FileControl>
<CreationDate>2008-08-11</CreationDate>
- <Source>
<SystemID>SAP4BSN</SystemID>
<MandantID>100</MandantID>
</Source>
- <Destination>
<SystemID>CWL</SystemID>
<MandantID>746</MandantID>
</Destination>
<SequenceNumber>000000004</SequenceNumber>
<Counter>000000001</Counter>
</FileControl>
- <Message>
- <PartyRegistrationID>
<ID>2101576347</ID>
<Type>RG</Type>
<ID>2101576347</ID>
<Type>AG</Type>
</PartyRegistrationID>
<CustomerGroupID>02</CustomerGroupID>
<Name>Lewicki</Name>
<Subname>Hans Bruno Michel</Subname>
<DateTime>2008-08-11T23:59:59</DateTime>
- <DefaultOfPayment>
<MessageID>00000001</MessageID>
<GrossAmountBefore>0.0</GrossAmountBefore>
<GrossAmountCurrent>-17.9</GrossAmountCurrent>
<Currency>EUR</Currency>
<SettlementOfBalance>Nein</SettlementOfBalance>
<IncludingSubsidiaryClaim>Ja</IncludingSubsidiaryClaim>
</DefaultOfPayment>
- <ContractsWithDefaultOfPayment>
<ContractID>0148863732</ContractID>
</ContractsWithDefaultOfPayment>
- <Messagedetails>
- <ReturnDebitNote>
<MessageID>00000002</MessageID>
<KindOf>BA</KindOf>
<Reason>E2</Reason>
<Date>2008-08-11</Date>
<GrossAmount>-15.4</GrossAmount>
<Currency>EUR</Currency>
</ReturnDebitNote>
</Messagedetails>
</Message>
</Statemessages>
//XML end
I am using the following stored procedure to try this;
create or replace PROCEDURE CompleteSaveXML_1 AS
XMLMessage2 XMLTYPE;
v_parser dbms_xmlparser.Parser;
v_clob CLOB;
v_sent DATE;
v_doc xmldom.DOMDocument;
v_nl xmldom.DOMNodeList;
v_nFCL xmldom.DOMNodeList;
v_nFCN xmldom.DOMNode;
v_nFCSourceL xmldom.DOMNodeList;
v_nFCSourceN xmldom.DOMNode;
v_nFCDestinationL xmldom.DOMNodeList;
v_nFCDestinationN xmldom.DOMNode;
m_nl xmldom.DOMNodeList;
m_n xmldom.DOMNode;
v_n xmldom.DOMNode;
v_n3 xmldom.DOMNodeList;
v_n4 xmldom.DOMNode;
v_b xmldom.DOMNode;
v_d xmldom.DOMNode;
v_a xmldom.DOMNodeList;
v_c xmldom.DOMNodeList;
m_prg xmldom.DOMNodeList;
m_pr xmldom.DOMNode;
condf_nl xmldom.DOMNodeList;
condf_n xmldom.DOMNode;
msgdtl_nl xmldom.DOMNodeList;
msgdtl_n xmldom.DOMNode;
rtndbt_nl xmldom.DOMNodeList;
rtndbt_n xmldom.DOMNode;
dnlt_nl xmldom.DOMNodeList;
dnlt_n xmldom.DOMNode;
cancl_nl xmldom.DOMNodeList;
cancl_n xmldom.DOMNode;
conid_nl xmldom.DOMNodeList;
conid_n xmldom.DOMNode;
canclid_nl xmldom.DOMNodeList;
canclid_n xmldom.DOMNode;
par_ref number(10) :=0;
msgnum number(20):=0;
var1 number(30):=0;
rtnnum number(20):=0;
dnnum number(20):=0;
tpmsg number(20):=0;
condfpmt number(20):=0;
canclnum number(20):=0;
--Added the next variable
sequence_no number(20):=0;
--These are the new variables
condfpmt1 number(20):=0;
rtnnum1 number(20):=0;
dnnum1 number(20):=0;
tpmsg1 number(20):=0;
canclnum1 number(20):=0;
--changing
part_refid_value number(20);
parid_typ_n xmldom.DOMNode;
parid_typ_nl xmldom.DOMNodeList;
parid_id_nl xmldom.DOMNodeList;
parid_id_n xmldom.DOMNode;
party_ref_node xmldom.DOMNode;
var_pr_reg_typ VARCHAR2(2);
msgrtdbt_nl xmldom.DOMNodeList;
msgrtdbt_n xmldom.DOMNode;
kndrtdbt_nl xmldom.DOMNodeList;
kndrtdbt_n xmldom.DOMNode;
rsnrtdbt_nl xmldom.DOMNodeList;
rsnrtdbt_n xmldom.DOMNode;
datrtdbt_nl xmldom.DOMNodeList;
datrtdbt_n xmldom.DOMNode;
grssrtdbt_nl xmldom.DOMNodeList;
grssrtdbt_n xmldom.DOMNode;
currtdbt_nl xmldom.DOMNodeList;
currtdbt_n xmldom.DOMNode;
rtnnum2 number(20):=0;
msgdnlt_nl xmldom.DOMNodeList;
msgdnlt_n xmldom.DOMNode;
lvdnlt_nl xmldom.DOMNodeList;
lvdnlt_n xmldom.DOMNode;
datdnlt_nl xmldom.DOMNodeList;
datdnlt_n xmldom.DOMNode;
grsdnlt_nl xmldom.DOMNodeList;
grsdnlt_n xmldom.DOMNode;
curdnlt_nl xmldom.DOMNodeList;
curdnlt_n xmldom.DOMNode;
limdnlt_nl xmldom.DOMNodeList;
limdnlt_n xmldom.DOMNode;
lvimp number(20);
nullchk varchar2(30) ;
chk_flseq number(10);
fl_seq number(30);
--these are the new variables
TYPE tab_type IS TABLE OF FileControl%ROWTYPE;
t_tab_FC tab_type := tab_type();
TYPE tab_type1 IS TABLE OF MessageTab%ROWTYPE;
t_tab1 tab_type1 := tab_type1();
TYPE tab_type2 IS TABLE OF ContractsWithDefaultOfPayment%ROWTYPE;
t_tab2 tab_type2 := tab_type2();
TYPE tab_type3 IS TABLE OF CancellationTab%ROWTYPE;
t_tab3 tab_type3 := tab_type3();
TYPE tab_type4 IS TABLE OF ReturnDebitNoteTab%ROWTYPE;
t_tab4 tab_type4 := tab_type4();
TYPE tab_type5 IS TABLE OF DunningLettersTab%ROWTYPE;
t_tab5 tab_type5 := tab_type5();
cursor MessageCursor is
select * from OM_BSN_STATEMSGS
where PROCESSED is null AND SENT in(Select min(SENT) from OM_BSN_STATEMSGS
where PROCESSED is null)
order by sent asc;
v_statemsgs OM_BSN_STATEMSGS%ROWTYPE;
BEGIN
DBMS_OUTPUT.put_line('creating parser');
-- v_parser := DBMS_XMLPARSER.NEWPARSER;
v_parser := DBMS_XMLPARSER.NEWPARSER();
DBMS_OUTPUT.put_line('done creating');
DBMS_XMLPARSER.setValidationMode(v_parser, true);
DBMS_XMLPARSER.showWarnings(v_parser, true);
open MessageCursor;
loop
fetch MessageCursor into v_statemsgs;
exit when MessageCursor%NOTFOUND;
DBMS_XMLPARSER.PARSECLOB(P => v_parser, DOC => v_statemsgs.MESSAGE);
-- xmlparser.parse(v_parser, File_Location);
v_doc := xmlparser.getDocument(v_parser);
dbms_xmlparser.freeParser(v_parser); DBMS_OUTPUT.put_line('Step 1');
v_nFCL := xslprocessor.selectNodes(xmldom.makeNode(v_doc),'/Statemessages/FileControl');
v_nFCN := xmldom.item(v_nFCL,0);
Source
v_nFCSourceL := xslprocessor.selectNodes(xmldom.makeNode(v_doc),'/Statemessages/FileControl/Source');
v_nFCSourceN := xmldom.item(v_nFCSourceL,0);
Destination
v_nFCDestinationL := xslprocessor.selectNodes(xmldom.makeNode(v_doc),'/Statemessages/FileControl/Destination');
v_nFCDestinationN := xmldom.item(v_nFCDestinationL,0);
-- Populate tab type for ORFC
t_tab_FC.extend;
t_tab_FC(t_tab_FC.last).creation_date := to_date(xslprocessor.valueOf(v_nFCN,'CreationDate'),'YYYY-MM-DD');
t_tab_FC(t_tab_FC.last).src_sys_id := xslprocessor.valueOf(v_nFCSourceN,'SystemID');
t_tab_FC(t_tab_FC.last).src_mandant_id := xslprocessor.valueOf(v_nFCSourceN,'MandantID');
t_tab_FC(t_tab_FC.last).dest_sys_id := xslprocessor.valueOf(v_nFCDestinationN,'SystemID');
t_tab_FC(t_tab_FC.last).dest_mandant_id := xslprocessor.valueOf(v_nFCDestinationN,'MandantID');
t_tab_FC(t_tab_FC.last).seq_no := xslprocessor.valueOf(v_nFCN,'SequenceNumber');
t_tab_FC(t_tab_FC.last).counter := xslprocessor.valueOf(v_nFCN,'Counter');
--Saving the value of this seq_no so that it can be inserted in the message tab.
sequence_no:= xslprocessor.valueOf(v_nFCN,'SequenceNumber');
--Insert into ORFC TAB
fl_seq := xslprocessor.valueOf(v_nFCN,'SequenceNumber');
select count(*) into chk_flseq from FileControl where SEQ_NO =fl_seq;
if (chk_flseq =0) then
FOR each_FC IN t_tab_FC.first .. t_tab_FC.last LOOP
INSERT INTO FileControl
creation_date,
src_sys_id,
src_mandant_id,
dest_sys_id,
dest_mandant_id,
seq_no,
counter)
VALUES
t_tab_FC(each_FC).creation_date,
t_tab_FC(each_FC).src_sys_id ,
t_tab_FC(each_FC).src_mandant_id,
t_tab_FC(each_FC).dest_sys_id,
t_tab_FC(each_FC).dest_mandant_id,
t_tab_FC(each_FC).seq_no,
t_tab_FC(each_FC).counter
END LOOP;
end if;
DBMS_OUTPUT.put_line('Step 2');
if (chk_flseq =0) then /* chk the xml's filecontrol seq exists in filecontrltab */
-- Use XPATH syntax to assign values to he elements of the collection.
v_nl := xslprocessor.selectNodes(xmldom.makeNode(v_doc),'/Statemessages/Message');
tpmsg := xmldom.getLength(v_nl);
DBMS_OUTPUT.put_line('Message node length'||tpmsg);
if (tpmsg>0) then
FOR cur_emp IN 0 .. xmldom.getLength(v_nl) - 1 LOOP
v_n := xmldom.item(v_nl, cur_emp);
select (BISON_OM_MessageID.NEXTVAL) into var1 from dual;
t_tab1.extend;
t_tab1(t_tab1.last).message_id := var1;
t_tab1(t_tab1.last).seq_no := sequence_no;
---party reg
m_prg := xslprocessor.selectNodes(v_n,'PartyRegistrationID');
FOR Ref_Id_Loop IN 0 .. xmldom.getLength(m_prg) - 1 LOOP
party_ref_node := xmldom.item(m_prg,0);
part_refid_value := xslprocessor.valueOf(party_ref_node,'.');
end loop;
m_pr := xmldom.item(m_prg, 0);
--changing
--chang id
parid_id_nl := xslprocessor.selectNodes(m_pr,'ID');
DBMS_OUTPUT.put_line('Going to read PartyRegistrationID');
FOR cur_parid_id IN 0 .. xmldom.getLength(parid_id_nl) - 1 LOOP
parid_id_n := xmldom.item(parid_id_nl,cur_parid_id);
DBMS_OUTPUT.put_line('Value of id:'|| xslprocessor.valueOf(parid_id_n,'.'));
t_tab1(t_tab1.last).party_ref_id := xslprocessor.valueOf(parid_id_n,'.');
exit;
end loop ;
---- change id
parid_typ_nl := xslprocessor.selectNodes(m_pr,'Type');
FOR cur_parid_typ IN 0 .. xmldom.getLength(parid_typ_nl) - 1 LOOP
parid_typ_n := xmldom.item(parid_typ_nl,cur_parid_typ);
var_pr_reg_typ := xslprocessor.valueOf(parid_typ_n,'.');
if var_pr_reg_typ='RG' then
t_tab1(t_tab1.last).PARTY_REG_TYPE_RG := var_pr_reg_typ;
elsif var_pr_reg_typ='AG' then
t_tab1(t_tab1.last).PARTY_REG_TYPE_AG := var_pr_reg_typ;
end if;
end loop;
--Chang
-- t_tab1(t_tab1.last).PARTY_REG_TYPE_AG := xslprocessor.valueOf(m_pr,'Type');
par_ref :=xslprocessor.valueOf(m_pr,'ID');
t_tab1(t_tab1.last).customer_grp_id := xslprocessor.valueOf(v_n,'CustomerGroupID');
t_tab1(t_tab1.last).name := xslprocessor.valueOf(v_n,'Name');
t_tab1(t_tab1.last).subname := xslprocessor.valueOf(v_n,'Subname');
t_tab1(t_tab1.last).datetime := xslprocessor.valueOf(v_n,'DateTime');
DBMS_OUTPUT.put_line('Step 3 ContractsWithDefaultOfPayment');
m_nl := xslprocessor.selectNodes(v_n,'DefaultOfPayment');
m_n := xmldom.item(m_nl, 0);
t_tab1(t_tab1.last).payment_msg_id := xslprocessor.valueOf(m_n,'MessageID');
t_tab1(t_tab1.last).gross_amt_before := xslprocessor.valueOf(m_n,'GrossAmountBefore');
t_tab1(t_tab1.last).gross_amt_current := xslprocessor.valueOf(m_n,'GrossAmountCurrent');
t_tab1(t_tab1.last).currency := xslprocessor.valueOf(m_n,'Currency');
t_tab1(t_tab1.last).settlemen_of_balance := xslprocessor.valueOf(m_n,'SettlementOfBalance');
t_tab1(t_tab1.last).including_subsidiary_claim := xslprocessor.valueOf(m_n,'IncludingSubsidiaryClaim');
condf_nl := xslprocessor.selectNodes(v_n,'ContractsWithDefaultOfPayment');
condf_n := xmldom.item(condf_nl,0);
condfpmt := xmldom.getLength(condf_nl);
if (condfpmt > 0) then
conid_nl := xslprocessor.selectNodes(condf_n,'ContractID');
FOR cur_conid IN 0 .. xmldom.getLength(conid_nl) - 1 LOOP
conid_n := xmldom.item(conid_nl,cur_conid);
t_tab2.extend;
t_tab2(t_tab2.last).message_id := var1;
t_tab2(t_tab2.last).contract_id := xslprocessor.valueOf(conid_n,'.');
end loop;
condfpmt1 := 1;
end if;
cancl_nl := xslprocessor.selectNodes(v_n,'Cancellation');
cancl_n := xmldom.item(cancl_nl,0);
DBMS_OUTPUT.put_line('No of cancellations'||xmldom.getLength(cancl_nl) );
canclnum := xmldom.getLength(cancl_nl) ;
if (canclnum > 0) then
canclid_nl := xslprocessor.selectNodes(cancl_n,'MessageID');
FOR cur_canclid IN 0 .. xmldom.getLength(canclid_nl) - 1 LOOP
canclid_n := xmldom.item(canclid_nl,cur_canclid);
t_tab3.extend;
t_tab3(t_tab3.last).message_id := var1;
t_tab3(t_tab3.last).cancellation_msg_id := xslprocessor.valueOf(canclid_n,'.');
end loop;
canclnum1 :=1;
end if; -- canclnum
msgdtl_nl := xslprocessor.selectNodes(v_n,'Messagedetails');
msgnum := xmldom.getLength(msgdtl_nl) ;
dbms_output.put_line('msgggg::::'||msgnum);
if (msgnum >0) then
msgdtl_n := xmldom.item(msgdtl_nl,0);
rtndbt_nl := xslprocessor.selectNodes(msgdtl_n,'ReturnDebitNote');
rtndbt_n := xmldom.item(rtndbt_nl,0);
rtnnum := xmldom.getLength(rtndbt_nl) ;
if (rtnnum >0) then
--return debit note
msgrtdbt_nl := xslprocessor.selectNodes(rtndbt_n,'MessageID');
kndrtdbt_nl := xslprocessor.selectNodes(rtndbt_n,'KindOf');
rsnrtdbt_nl := xslprocessor.selectNodes(rtndbt_n,'Reason');
datrtdbt_nl := xslprocessor.selectNodes(rtndbt_n,'Date');
grssrtdbt_nl := xslprocessor.selectNodes(rtndbt_n,'GrossAmount');
currtdbt_nl := xslprocessor.selectNodes(rtndbt_n,'Currency');
rtnnum2 :=0;
FOR cur_msgrtndbt IN 0 .. xmldom.getLength(msgrtdbt_nl) - 1 LOOP
msgrtdbt_n := xmldom.item(msgrtdbt_nl,cur_msgrtndbt);
kndrtdbt_n := xmldom.item(kndrtdbt_nl,cur_msgrtndbt);
rsnrtdbt_n := xmldom.item(rsnrtdbt_nl,cur_msgrtndbt);
datrtdbt_n := xmldom.item(datrtdbt_nl,cur_msgrtndbt);
grssrtdbt_n := xmldom.item(grssrtdbt_nl,cur_msgrtndbt);
currtdbt_n := xmldom.item(currtdbt_nl,cur_msgrtndbt);
t_tab4.extend;
t_tab4(t_tab4.last).message_id := var1;
t_tab4(t_tab4.last).ret_debitnote_msg_id := xslprocessor.valueOf(msgrtdbt_n,'.');
t_tab4(t_tab4.last).kind_of := xslprocessor.valueOf(kndrtdbt_n,'.');
t_tab4(t_tab4.last).Reason := xslprocessor.valueOf(rsnrtdbt_n,'.');
t_tab4(t_tab4.last).debit_note_date := to_date(xslprocessor.valueOf(datrtdbt_n,'.'),'YYYY-MM-DD');
t_tab4(t_tab4.last).gross_amt := xslprocessor.valueOf(grssrtdbt_n,'.');
t_tab4(t_tab4.last).currency := xslprocessor.valueOf(currtdbt_n,'.');
rtnnum1 :=rtnnum1 + 1;
rtnnum2 := rtnnum2 + 1;
dbms_output.put_line('message_id::::'||var1);
dbms_output.put_line('rtnnum2::::'||rtnnum2);
dbms_output.put_line('ret_debitnote_msg_id:::'||t_tab4(t_tab4.last).ret_debitnote_msg_id);
end loop;
----return debit note
t_tab4(t_tab4.last).message_id := var1 ;
t_tab4(t_tab4.last).ret_debitnote_msg_id := xslprocessor.valueOf(rtndbt_n,'MessageID');
t_tab4(t_tab4.last).kind_of := xslprocessor.valueOf(rtndbt_n,'KindOf');
t_tab4(t_tab4.last).reason := xslprocessor.valueOf(rtndbt_n,'Reason');
t_tab4(t_tab4.last).debit_note_date := to_date(xslprocessor.valueOf(rtndbt_n,'Date'),'YYYY-MM-DD');
t_tab4(t_tab4.last).gross_amt := xslprocessor.valueOf(rtndbt_n,'GrossAmount');
t_tab4(t_tab4.last).currency := xslprocessor.valueOf(rtndbt_n,'Currency');
rtnnum1 :=1;
end if;
dnlt_nl := xslprocessor.selectNodes(msgdtl_n,'DunningLetter');
dnlt_n := xmldom.item(dnlt_nl, 0);
dnnum := xmldom.getLength(dnlt_nl) ;
if (dnnum >0) then
-- t_tab5.extend;
--dunning letter
msgdnlt_nl := xslprocessor.selectNodes(dnlt_n,'MessageID');
lvdnlt_nl := xslprocessor.selectNodes(dnlt_n,'Level');
datdnlt_nl := xslprocessor.selectNodes(dnlt_n,'Date');
grsdnlt_nl := xslprocessor.selectNodes(dnlt_n,'GrossAmount');
curdnlt_nl := xslprocessor.selectNodes(dnlt_n,'Currency');
limdnlt_nl := xslprocessor.selectNodes(dnlt_n,'LevelImprovement');
FOR cur_msgdnlt IN 0 .. xmldom.getLength(msgdnlt_nl) - 1 LOOP
msgdnlt_n := xmldom.item(msgdnlt_nl,cur_msgdnlt);
lvdnlt_n := xmldom.item(lvdnlt_nl,cur_msgdnlt);
datdnlt_n := xmldom.item(datdnlt_nl,cur_msgdnlt);
grsdnlt_n := xmldom.item(grsdnlt_nl,cur_msgdnlt);
curdnlt_n := xmldom.item(curdnlt_nl,cur_msgdnlt);
limdnlt_n := xmldom.item(limdnlt_nl,cur_msgdnlt);
t_tab5.extend;
t_tab5(t_tab5.last).message_id := var1;
t_tab5(t_tab5.last).dunning_msg_id := xslprocessor.valueOf(msgdnlt_n,'.');
t_tab5(t_tab5.last).d_level := xslprocessor.valueOf(lvdnlt_n,'.');
t_tab5(t_tab5.last).dunning_date := to_date(xslprocessor.valueOf(datdnlt_n,'.'),'YYYY-MM-DD');
t_tab5(t_tab5.last).gross_amt := xslprocessor.valueOf(grsdnlt_n,'.');
t_tab5(t_tab5.last).currency := xslprocessor.valueOf(curdnlt_n,'.');
lvimp := xmldom.getLength(limdnlt_nl);
begin
t_tab5(t_tab5.last).level_improvement := xslprocessor.valueOf(limdnlt_n,'.');
EXCEPTION
WHEN OTHERS THEN
t_tab5(t_tab5.last).level_improvement := null;
end;
dnnum1 :=dnnum1 + 1;
-- dnnum2 := dnnum2 + 1;
dbms_output.put_line('message_id::::'||var1);
end loop;
----dunning letter
t_tab5(t_tab5.last).message_id := var1;
t_tab5(t_tab5.last).dunning_msg_id := xslprocessor.valueOf(dnlt_n,'MessageID');
t_tab5(t_tab5.last).d_level := xslprocessor.valueOf(dnlt_n,'Level');
t_tab5(t_tab5.last).dunning_date := to_date(xslprocessor.valueOf(dnlt_n,'Date'),'YYYY-MM-DD');
t_tab5(t_tab5.last).gross_amt := xslprocessor.valueOf(dnlt_n,'GrossAmount');
t_tab5(t_tab5.last).currency := xslprocessor.valueOf(dnlt_n,'Currency');
t_tab5(t_tab5.last).level_improvement := xslprocessor.valueOf(dnlt_n,'LevelImprovement');
dnnum1 :=1; */
end if;
end if;
END LOOP;
-- Insert data into the real EMP table from the table collection.
-- Form better performance multiple collections should be used to allow
-- bulk binding using the FORALL construct but this would make the code
-- too long-winded for this example.
DBMS_OUTPUT.put_line('Step 5');
FOR cur_emp IN t_tab1.first .. t_tab1.last LOOP
INSERT INTO MessageTab
message_id,
PARTY_REF_ID,
PARTY_REG_TYPE_AG,
party_reg_type_rg,
customer_grp_id,
name,
subname,
datetime,
payment_msg_id,
gross_amt_before,
gross_amt_current,
currency,
settlemen_of_balance,
including_subsidiary_claim,
seq_no)
VALUES
t_tab1(cur_emp).message_id,
t_tab1(cur_emp).PARTY_REF_ID,
t_tab1(cur_emp).PARTY_REG_TYPE_AG,
t_tab1(cur_emp).PARTY_REG_TYPE_RG,
t_tab1(cur_emp).customer_grp_id,
t_tab1(cur_emp).name,
t_tab1(cur_emp).subname,
t_tab1(cur_emp).datetime,
t_tab1(cur_emp).payment_msg_id,
t_tab1(cur_emp).gross_amt_before,
t_tab1(cur_emp).gross_amt_current,
t_tab1(cur_emp).currency,
t_tab1(cur_emp).settlemen_of_balance,
t_tab1(cur_emp).including_subsidiary_claim,
t_tab1(cur_emp).seq_no
END LOOP;
DBMS_OUTPUT.put_line('Step 6');
if (condfpmt1 > 0) then
FOR cur_cnf IN t_tab2.first .. t_tab2.last LOOP
INSERT INTO ContractsWithDefaultOfPayment
(message_id,contract_id)
values
(t_tab2(cur_cnf).message_id,t_tab2(cur_cnf).contract_id );
end loop;
end if; -- condfpmt
if (canclnum1 > 0) then
FOR cur_cancl IN t_tab3.first .. t_tab3.last LOOP
INSERT INTO CancellationTab
(message_id,cancellation_msg_id)
VALUES
(t_tab3(cur_cancl).message_id,t_tab3(cur_cancl).cancellation_msg_id);
END LOOP;
end if;
DBMS_OUTPUT.put_line('Step 7');
if (rtnnum1 >0) then
FOR cur_rtndb IN t_tab4.first .. t_tab4.last LOOP
INSERT INTO ReturnDebitNoteTab
(message_id,
ret_debitnote_msg_id,
kind_of,
reason,
debit_note_date,
gross_amt,
currency
VALUES
(t_tab4(cur_rtndb).message_id,
t_tab4(cur_rtndb).ret_debitnote_msg_id,
t_tab4(cur_rtndb).kind_of,
t_tab4(cur_rtndb).reason,
t_tab4(cur_rtndb).debit_note_date,
t_tab4(cur_rtndb).gross_amt,
t_tab4(cur_rtndb).currency);
END LOOP;
end if;
if (dnnum1 >0) then
FOR cur_dnl IN t_tab5.first .. t_tab5.last LOOP
INSERT INTO DunningLettersTab
(message_id,
dunning_msg_id,
d_level,
dunning_date,
gross_amt,
currency,
level_improvement)
VALUES
(t_tab5(cur_dnl).message_id,
t_tab5(cur_dnl).dunning_msg_id,
t_tab5(cur_dnl).d_level,
t_tab5(cur_dnl).dunning_date,
t_tab5(cur_dnl).gross_amt,
t_tab5(cur_dnl).currency,
t_tab5(cur_dnl).level_improvement
END LOOP;
DBMS_OUTPUT.put_line('Step 8');
end if; -- dnn
end if; -- top msg
end if; --- fl_seq chk
COMMIT;
-- Free any resources associated with the document now it
-- is no longer needed.
xmldom.freeDocument(v_doc);
/* refresh array */
t_tab_FC.delete;
t_tab1.delete;
t_tab2.delete;
t_tab3.delete;
t_tab4.delete;
t_tab5.delete;
/* refsh */
end loop;
close MessageCursor;
END ;
//Errors thrown by Oracle always show a line number (even if it points to the FOR loop that the error occurred within). When you run it, what is the error stack that is being returned. Copy and paste that, don't summarize it.
If you are still uncertain, add a final
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);to have it written out where your normal dbms_output goes. This is your friend in 10g for tracking down errors.
"But as soon as i add a prefix in the header everything works fine."
Is that header in the sample XML you provided? Regardless what are you adding? Your data is a clob so you can always tweak it before converting it to a DOMDocument just by doing simple string manipulation.
Since you are in 10g, you should be using dbms_xmldom instead of xmldom. I think xmldom is just a synonym for dbms_xmldom though. Review the dbms_xmldom documentation. You can go straight from a clob to a DOMDocument via DBMS_XMLDOM.NEWDOMDOCUMENT. You can also parse the document completely using dbms_xmldom calls instead of xslprocessor calls.
Other random things to evaluate:
Consider turning
FOR each_FC IN t_tab_FC.first .. t_tab_FC.last LOOP
INSERT INTO FileControl
into a
FORALL i IN t_tab_FC.first .. t_tab_FC.last LOOP
INSERT INTO FileControl
...Better performance because one two context switches (PL/SQL -> SQL -> PL/SQL) instead of 2*n switches.
I like this construct better
TYPE tab_type IS TABLE OF FileControl%ROWTYPE INDEX BY BINARY_INTEGER;
t_tab_FC tab_type := tab_type;because then you don't have to t_tab_FC.extend;you can just do something like index := 1;
LOOP
t_tab_FC(index).creation_date := <whatever>;
index := index + 1;
END LOOPYou also have the option of parsing your XML as a XMLType, including purely in SQL, but you can research that avenue at a later date.
Forgot to mention, wrap any code examples in [ pre ] [ pre ] (without the spaces) to retain your formatting. -
How to parse whole xml elements into a java String
hello everybody,
I am trying to parse whole xml into a string for example
my xml file is as below:
<root>
<element>
<data id="1">1</data>
</element>
<element>
<data id="2">2</data>
</element>
</root>
in java whole data should be transfered as
String xmlString ="<root><element><data id=\"1\">1</data></element><element><data id=\"2\">2</data></element></root>";or in a simple way can xml be copied into a string? any assistance ...
thanQ in Advance.
Han.This code is to convert xml document to a string.
try {
javax.xml.transform.TransformerFactory tfactory = TransformerFactory.newInstance();
javax.xml.transform.Transformer xform = tfactory.newTransformer();
javax.xml.transform.Source src = new DOMSource(xmlString);
java.io.StringWriter writer = new StringWriter();
StreamResult result = new javax.xml.transform.stream.StreamResult(writer);
xform.transform(src, result);
//System.out.println(writer.toString());
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}catch(Exception ex )
ex.printStackTrace();
} -
How to parse the xml file using servlet
My scenario is like this:
<b>FILE-->XI-->J2EE Application</b>
XI sends the xml file to j2ee application. My servlet receives the file in HTTPRequest string.
How to parse that file using servlets.I should get the xml file as it is and should be displayed in the browser.
Can anyone please help me with code, its urgent.
Please help me!Download this java code
http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
in your servlet code you can write
public void doPost(req,resp){
DefaultHandler handler = new Echo02();
handler.parse(req.getInputStream());
Offcourse you will need to modify the code of Echo02 class a bit to suit your requirement which would finally retrun you a string and you can then write it using
respose.getWriter().write(responseString); -
How to Parse an XML file using SAXParser in java.
Hi all
Am a bit new to XML files and have no idea about SAXParsers ... Now my problem is to parse this XML file below
<?xml version="1.0" encoding="UTF-8"?>
<sc:memory_segmentation xmlns:sc="sc_memory_segmentation.xsd">
<sc:architecture name="MPC55xx"></sc:architecture>
<sc:derivative name=""></sc:derivative>
<sc:configuration name=""></sc:configuration>
<sc:memory name="Internal ROM" type="ROM">
<sc:area-list>
<sc:area name="Bootmanager" type="BOOTMANAGER">
<sc:segment-list>
<sc:segment name="ROM page 1">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Bootloader SWE" type="BOOTLOADER">
<sc:segment-list>
<sc:segment name="ROM page 2">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 3">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 1" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 4">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 5">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 6">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="ROM page 7">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 2" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 8">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 3" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 9">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
<sc:area name="Application SWE 4" type="APPLICATION">
<sc:segment-list>
<sc:segment name="ROM page 10">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
</sc:area-list>
</sc:memory>
<sc:memory name="Internal RAM" type="RAM">
<sc:area-list>
<sc:area name="RAM" type="RAM">
<sc:segment-list>
<sc:segment name="RAM page 1">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 2">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 3">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 4">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="RAM page 5">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
</sc:area-list>
</sc:memory>
<sc:memory name="Internal EEPROM" type="EEPROM">
<sc:area-list>
<sc:area name="EEPROM" type="EEPROM">
<sc:segment-list>
<sc:segment name="EEPROM page 1">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 2">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 3">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 4">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
<sc:segment name="EEPROM page 5">
<sc:start></sc:start>
<sc:end></sc:end>
</sc:segment>
</sc:segment-list>
</sc:area>
</sc:area-list>
</sc:memory>
</sc:memory_segmentation> And from this file I need to make 3 Hashtables out of it one for ROM , RAM and EEPROM containg Segment information i.e. Segment start and end addresses and Area type of the segment....
If anyone could at least guide me with the basic commands and structure of the parser it would be really really great ...
Thanks a lot
AnishaNormally if you have no idea about X, the first thing you should do is google "X tutorial". You will find plenty of them out there. And the advantage is, they are better written than whatever we spend two minutes throwing together here. Not to mention that it saves us the two minutes.
But if you have specific questions with your SAX parser when you get it going, then ask them here. Actually, ask them in the XML forum here, not this one. -
How to parse multiple xml documents from single buffer
Hello,
I am trying to use jaxb 2.0 to parse a buffer which contains multiple xml documents. However, it seems that it is meant to only parse a single document at a time and throws an exception when it gets to the 2nd document.
Is there a way I can tell jaxb to only parse the first complete document and not fetch the next one out of the buffer? Or what is the most efficient way to separate the buffer into two documents without parsing it manually. If I have to search the buffer for the next document root and then split the buffer, it seems like that defeats the purpose of using jaxb as the parser.
I am using the Unmarshaller.unmarshall method and the exception I am getting is:
org.xml.sax.SAXParseException: Illegal character at end of document, <.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:476)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:198)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:167)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
Thank you for your helpIt's just like any other XML parser, it's only designed to parse one XML document. If you have something that concatenates two XML documents together (that's what your "buffer" sounds like), then stop doing that.
-
I need some help to parse an XML String instead of an XML file. The string can be like.
String myRecords =
"<data>"+
" <employee>"+
" <name>John</name>"+
" <Designation>Manager</Designation>"+
" </employee>"+
" <employee>"+
" <name>Sara</name>"+
" <Designation>Clerk</Designation>"+
" </employee>"+
"<data>"+I tried it in a servlet, it and it worked. The entire code is long. But here it is most of it:
assuming that x is a string and has the xml of
<?xml version="1.0" ?>
- <company>
- <employee>
<firstname>Tom</firstname>
<lastname>Cat</lastname>
</employee>
- <employee>
<firstname>Paul</firstname>
<lastname>Enderson</lastname>
</employee>
- <employee>
<firstname>George</firstname>
<lastname>Jungle</lastname>
</employee>
</company>
=========================
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(*x*));
Document doc = db.parse(inStream);
doc.getDocumentElement().normalize();
out.println("Root element " + doc.getDocumentElement().getNodeName() + "<BR>");
NodeList nodeLst = doc.getElementsByTagName("employee");
out.println("Information of all employees<BR>");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("firstname");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
out.println("First Name : " + ((Node) fstNm.item(0)).getNodeValue() + "<BR>");
NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
NodeList lstNm = lstNmElmnt.getChildNodes();
out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue() + "<BR>");
} catch (Exception e) {
System.out.println(e);
out.close();
==============
The output is
Root element company
Information of all employees
First Name : Tom
Last Name : Cat
First Name : Paul
Last Name : Enderson
First Name : George
Last Name : Jungle -
How to parse SOAP XML output and load to oracle9i table
Below is the SOAP output response and I need to load the data into oracle 9i database tables.
I am able to parse regular XML without namespaces but unable to parse the data with namespaces.
I would need help in parsing this XML.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2011-11-04T23:16:08.437Z</u:Created>
<u:Expires>2011-11-04T23:21:08.437Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<AssetGetListResponse xmlns="http://dev.services.xerox.com">
<AssetGetListResult xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:AssetFeed>
<a:AccountID>de5862bf-f223-e011-bd3b-0024e861b15c</a:AccountID>
<a:AccountName>MPS-API Sandbox</a:AccountName>
<a:AssetID>ecf1545a-f1e9-e011-8a8a-0024e861b15c</a:AssetID>
<a:AssetNumber>57119B28</a:AssetNumber>
<a:AssetTag3rdParty i:nil="true"/>
<a:ChargebackCodeID>1a5962bf-f223-e011-bd3b-0024e861b15c</a:ChargebackCodeID>
<a:ContractNumber i:nil="true"/>
<a:ContractTypeDescription i:nil="true"/>
<a:ControlID i:nil="true"/>
<a:Group i:nil="true"/>
<a:GroupID i:nil="true"/>
<a:InScope>false</a:InScope>
<a:MACAddress>0000AA713E97</a:MACAddress>
<a:Manufacturer>Xerox</a:Manufacturer>
<a:Model>WorkCentre Pro 265</a:Model>
<a:ModifiedDate>2011-11-02T16:52:12.947Z</a:ModifiedDate>
<a:PricePlanID>c25a62bf-f223-e011-bd3b-0024e861b15c</a:PricePlanID>
<a:SerialNumber>UTU101993N</a:SerialNumber>
<a:VersionNumber>634558495329470000</a:VersionNumber>
</a:AssetFeed>
<a:AssetFeed>
<a:AccountID>de5862bf-f223-e011-bd3b-0024e861b15c</a:AccountID>
<a:AccountName>MPS-API Sandbox</a:AccountName>
<a:AssetID>b33b5160-f1e9-e011-8a8a-0024e861b15c</a:AssetID>
<a:AssetNumber>7EE42ADC</a:AssetNumber>
<a:AssetTag3rdParty i:nil="true"/>
<a:ChargebackCodeID>1a5962bf-f223-e011-bd3b-0024e861b15c</a:ChargebackCodeID>
<a:ContractNumber i:nil="true"/>
<a:ContractTypeDescription i:nil="true"/>
<a:ControlID i:nil="true"/>
<a:Group i:nil="true"/>
<a:GroupID i:nil="true"/>
<a:InScope>false</a:InScope>
<a:MACAddress>0800379B4C2A</a:MACAddress>
<a:Manufacturer>Xerox</a:Manufacturer>
<a:Model>WorkCentre 7428</a:Model>
<a:ModifiedDate>2011-11-02T16:52:14.383Z</a:ModifiedDate>
<a:PricePlanID>c25a62bf-f223-e011-bd3b-0024e861b15c</a:PricePlanID>
<a:SerialNumber>PBB015012</a:SerialNumber>
<a:VersionNumber>634558495343830000</a:VersionNumber>
</a:AssetFeed>
</AssetGetListResult>
</AssetGetListResponse>
</s:Body>
</s:Envelope>
This is what I tried.
declare
lp_parser xmlParser.Parser;
lx_xmldoc xmlDom.DOMDocument;
ln_doc_node xmlDom.DOMNode;
lnl_product xmlDom.DOMNodeList;
lnl_meter xmlDom.DOMNodeList;
ln_product xmlDom.DOMNode;
ln_meter xmlDom.DOMNode;
li_product_cnt NUMBER;
li_product_max NUMBER;
li_meter_cnt NUMBER;
li_meter_max NUMBER;
lnl_asset_meter_nodes xmldom.DOMNodeList;
ln_asset_meter_node xmldom.DOMNode;
ls_batch_number VARCHAR2(30);
ldt_proc_dt DATE;
ls_batch_item VARCHAR2(30);
ls_place_id place.place_id%TYPE;
ls_product_id product.product_id%TYPE := ' ';
ls_contract_id contract.contract_id%TYPE;
li_contract_version contract.contract_version%TYPE;
li_contract_sequence contr_product.sequence%TYPE;
ls_meter_id meter_log.meter_id%TYPE;
ls_read_type meter_log.read_type%TYPE;
ldt_reading_dt meter_log.reading_dt%TYPE;
li_meter_value meter_log.meter_value%TYPE;
li_adjust_copies meter_log.meter_value%TYPE;
ls_meter_type VARCHAR2(20);
ls_serial_id product.serial_id%TYPE;
ls_meter_read_type VARCHAR2(50);
invalid_parsing EXCEPTION;
PRAGMA EXCEPTION_INIT(invalid_parsing, -20100);
BEGIN
FOR meter_xml_rec IN (SELECT SOAP_RESPONSE
FROM temp_table
WHERE call_id=2) LOOP
lp_parser := xmlparser.newParser;
xmlparser.parseClob(lp_parser, meter_xml_rec.SOAP_RESPONSE);
lx_xmldoc := xmlparser.getDocument(lp_parser);
xmlparser.freeParser(lp_parser);
ln_doc_node := xmlDom.makeNode(lx_xmldoc);
ls_batch_number := xslProcessor.valueOf(ln_doc_node, 'AssetGetListResponse/AssetGetListResult/AssetFeed/AccountID');
lnl_product := xslprocessor.selectNodes(ln_doc_node, 'AssetGetListResponse/AssetGetListResult/a:AssetFeed');
li_product_max := xmlDom.getLength(lnl_product)-1;
FOR li_product_cnt IN 0..li_product_max LOOP
ln_product := xmlDom.item(lnl_product, li_product_cnt);
ls_batch_item := xslProcessor.valueOf(ln_product, 'AccountName');
END LOOP;
END LOOP;
END;
OUTPUT:
=========================================
3:32:41 PM *
**3:32:41 PM ORA-20100: Error occurred while processing: Namespace prefix 'a' used but not declared.**
3:32:41 PM ORA-06512: at "SYS.XSLPROCESSOR", line 22
3:32:41 PM ORA-06512: at "SYS.XSLPROCESSOR", line 502
3:32:41 PM ORA-06512: at line 50
3:32:41 PM *** Script stopped due to error ***
3:32:41 PM End SQL Editor ExecutionHi,
Something like this :
lnl_product := xslprocessor.selectNodes(
ln_doc_node
, '/s:Envelope/s:Body/AssetGetListResponse/AssetGetListResult/a:AssetFeed'
, 'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/", xmlns="http://dev.services.xerox.com", xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS"'
li_product_max := xmlDom.getLength(lnl_product)-1;
FOR li_product_cnt IN 0..li_product_max LOOP
ln_product := xmlDom.item(lnl_product, li_product_cnt);
ls_batch_item := xslProcessor.valueOf(ln_product, 'a:AccountName', 'xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS"');
END LOOP;
...Or, using a single query :
SQL> SELECT extractValue(value(x), '/AssetFeed/AccountID', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AccountID
2 , extractValue(value(x), '/AssetFeed/AccountName', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AccountName
3 , extractValue(value(x), '/AssetFeed/AssetID', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AssetID
4 , extractValue(value(x), '/AssetFeed/AssetNumber', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as AssetNumber
5 , extractValue(value(x), '/AssetFeed/SerialNumber', 'xmlns="http://schemas.datacontract.org/2004/07/Xerox.MPS"') as SerialNumber
6 FROM temp_table t
7 , TABLE(
8 XMLSequence(
9 EXTRACT(
10 XMLType(t.soap_response)
11 , '/s:Envelope/s:Body/AssetGetListResponse/AssetGetListResult/a:AssetFeed'
12 , 'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/", xmlns="http://dev.services.xerox.com", xmlns:a="http://schemas.datacontract.org/2004/07/Xerox.MPS"'
13 )
14 )
15 ) x
16 WHERE t.call_id = 2
17 ;
ACCOUNTID ACCOUNTNAME ASSETID ASSETNUMBER SERIALNUMBER
de5862bf-f223-e011-bd3b-0024e861b15c MPS-API Sandbox ecf1545a-f1e9-e011-8a8a-0024e861b15c 57119B28 UTU101993N
de5862bf-f223-e011-bd3b-0024e861b15c MPS-API Sandbox b33b5160-f1e9-e011-8a8a-0024e861b15c 7EE42ADC PBB015012
Maybe you are looking for
-
I just opened a new I tunes account. The music that I purchased from an old account will not transfer to my new account & the old account email no longer exists it is (djbdeercreek613@com***t.net) and the password would not be accepted when we enter
-
I updated to Firefox 4.0.1 on Mac OSX 10.6.4. When I go to the "Bookmarks" drop down menu, there is no "Organize Bookmarks" command. How do I do the operations that were under that command such as add new folders, move bookmarks, export bookmarks, et
-
Why won't Painter erase a keyword on only ONE image at a time?
This has been driving me crazy - I'd like to delete a keyword on select images. I have hundreds of keywords and many are nested, so sometimes I screw up and need to erase selectively. I thought this problem was a bug, but it has persisted into LR 2.4
-
Scale and Crop - left with black bars
In Final Cut Express, I know the concept of "scale and crop" but when I am scaling and cropping, I am still left with black bars on each side of the video. It seems that I am able to crop/scale the white background and the video but not the canvas. H
-
I cant open my itunes in my computer
they say i need itunesmobiledll