Loop through CSV to create XML
Hello all, first and foremost I want to apologize if this has been answered somewhere, but I am looking to do the following:
I have 500 records I need put in XML format. The records are currently in CSV format. I can use curl to upload a record in XML format using our applications API. I was under the impression that I could generate 1 large XML file and upload the entire group.
I have a script that will read in data from a CSV and output it to a file in XML format. I got the script the way I thought I needed it working, which was to create a new xml file, append a line to it, then loop through the csv and echo my string repeatedly inputing the variables from the CSV file. I could then upload the XML file where I needed it.
As it turns out, it seems the API will only allow me to upload 1 record at a time. (ALMOST pointless IMO.) So what I am looking to do is change the way the script loops through the CSV file, and instead of creating 1 large file, I would like the script to loop through the CSV one line at a time, create the XML file of only 1 record, upload it using curl, delete itself (or its contents) and repeat that process throughout the entire CSV file.
I am just getting familiar with loops, so Im not sure how I would even start this process, or even word what I want properly to search google. (Which I have been for the last two days, thats how I frankenstiened what I have below. Any help would be greatly appreciated.
The script is as follows:
#!/bin/bash
echo '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' >> xmldata.xml
#:Read variables from XMLInput.csv:#
while read inputline;do
line0="$(echo $inputline | cut -d, -f1)"
line1="$(echo $inputline | cut -d, -f2)"
#:Set auto increment ID:#
idAdd0=$((idAdd0 +1))
#:removes trailing alpha characters leaving only the IP address:#
cutLine0=${line0//[^0-9.]/}
#:Strips trailing octet and appends .1:#
startIP=`echo $cutLine0 | sed 's/.[0-9]*$/.1/'`
#:Strips trailing octet and appens 254:#
endIP=`echo $cutLine0 | sed 's/.[0-9]*$/.254/'`
#:echos line to txt file as XML:#
echo "<network_segment><id>"$idAdd0"</id><name>$line0</name><starting_address>$startIP</starting_address><ending_address>$endIP</ending_address><distribution_point/><url/><netboot_server/><swu_server/><building>$line1</building><department/><override_buildings>false</override_buildings><override_departments>false</override_departments></network_segment>" >> xmldata.xml
done < XMLInput.csv
exit 0
What I ended up doing was having the script create 500 separate XML files in a folder by adding my auto increment variable to the XML file name,
then curling each file as a separate entry. A litte dirtier than I wanted, but in the end, I didn't have to manually enter 500 subnets
and define there locations in a website. Job Done.
Script if interested:
#!/bin/bash
#:Read variables from XMLInput.csv:#
while read inputline;do
line0="$(echo $inputline | cut -d, -f1)"
line1="$(echo $inputline | cut -d, -f2)"
echo
#:Set auto increment ID:#
idAdd0=$((idAdd0 +1))
#:removes trailing alpha characters leaving only the IP address:#
cutLine0=${line0//[^0-9.]/}
#:Strips trailing octet and appends .1:#
startIP=`echo $cutLine0 | sed 's/.[0-9]*$/.1/'`
#:Strips trailing octet and appens 254:#
endIP=`echo $cutLine0 | sed 's/.[0-9]*$/.254/'`
#:echos line to txt file as XML:#
echo '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'"<network_segment><id>"$idAdd0"</id><name>$line0</name><starting_address>
$startIP</starting_address><ending_address>$endIP</ending_address><distribution_point/><url/><netboot_server/><swu_server/><building>$line1</building>
<department/><override_buildings>false</override_buildings><override_departments>false</override_departments></network_segment>" >> xmldata$idAdd0.xml
#:upload XML file to JSS:#
`curl -k -v -u account:Password https://server address/JSSResource/networksegments/name/SegmentName -T "xmldata$idAdd0.xml" -X POST`
done < XMLInput.csv
exit 0
Similar Messages
-
Hi,
I want to loop through each column of a CSV file.
And while looping each column, I want to loop each row
starting with the 2st row.
I wrote the code as below, but it is looping through the rows
starting from row 1.
How do I make it start the loop as from row 2 in the CSV ?
(see code below)
Can someone tell me how to do this?
Thx
<!--- get and read the CSV-TXT file --->
<cffile action="read" file="C:\Documents and
Settings\user\Desktop\EM-CSV\test.csv" variable="csvfile">
<!--- loop through the CSV-TXT file on line breaks and
insert into database --->
<table border="1">
<cfloop index="index" list="#csvfile#"
delimiters="#chr(10)##chr(13)#">
<!--- <cfoutput>#listgetAt('#index#',1,
',')#</cfoutput><br> --->
<tr>
<td><cfoutput>#index#</cfoutput></td>
<td><cfoutput>#listgetAt('#index#',2,
',')#</cfoutput></td>
<td><cfoutput>#listgetAt('#index#',3,
',')#</cfoutput></td>
</tr>
</cfloop>
</table>Hello, your code works perfectly.
Now I am having a slight problem with it.
I have added the code to check whether a particular cell of
the CSV is blank. (see code below)
But it is giving me error message.
Can you please tell me what am doing wrong?
Thx
<!--- loop through the CSV-TXT file on line breaks and
insert into database --->
<cfset isRowTwoOrLater=false>
<table border="1">
<cfloop index="row" list="#csvfile#"
delimiters="#chr(10)##chr(13)#">
<cfif isRowTwoOrLater>
<tr>
<cfif #listgetAt(row,1, ',')# neq ''> <!--- I HAVE
ADDED THIS PART TO CHECK WHETHER IT IS BLANK --->
<td><cfoutput>#listgetAt(row,1,
',')#</cfoutput></td>
<cfelse>
<td><cfoutput>It is
blank</cfoutput></td>
</cfif>
<td><cfoutput>#listgetAt(row,2,
',')#</cfoutput></td>
<td><cfoutput>#listgetAt(row,3,
',')#</cfoutput></td>
</tr>
<cfelse>
<cfset isRowTwoOrLater = true>
</cfif>
</cfloop>
</table> -
Script code sample for looping through the records from xml data file in formCalc script
Hi
I have a xml data file which contains a sequence of repeating applicant data like given below
US
II
CEO
Mr
111111111
0000000111
GuarantorA
111
IN
11111
WILLIAMS1
R3
KENNETH1
City1GU
PA
1934-03-14
[email protected]
GU
R
113 Lazlo LaneCA
Suite 3500CA
OaklandCA
TX
11345
AL
I want to assign a textfield with a value based on the value of coap_flag.
So i need to loop through all the record and check the value of coap_flag and then assign the textfield a value based on that.
I am new to Adobe livecycle...Please help me how it can be done.
I have developed something like this
foreach Item in ($record.applicant[*].coap_flag) do
test.value=Item
if(test.value=="MA")then
concat($record.applicant.first_name,$record.applicant.middle_name)endif
endforUsing the data you posted in the forum, I copied it a couple of times to give multiple records and used this code to extract the different values that you wanted. I had to wrap it in a <root> node that I called root (to make it valid XML). In my case I wrote the extracted values to a field, but in your case you can do whatever you want with them. Note that this was done in javascript:<br /><br />var currentElement;<br />var obj;<br /><br />//Get the nodes below the root node in the dataDom<br />obj = xfa.datasets.data.root.nodes;<br /><br />//Set an initial value for the textField<br />TextField1.rawValue = "The values of the coap_flag are: ";<br /><br />//Loop through the nodes in the obj set <br />for (i=0; i< obj.length ; i++){<br /> //set the currentElement to the 1st child node<br /> currentElement = obj.item(i);<br /> //Check to see if it is an applicant node<br /> if (currentElement.name == "applicant"){<br /> //It is an applican, now find the coap_flag node value and write it to the text field<br /> TextField1.rawValue += "\n" + xfa.resolveNode("xfa.datasets.data.root.applicant[" + i + "]").coap_flag.value;<br /> }<br />}
-
Loop through the records from xml data file in formCalc script
Hi
I have a xml data file which contains a sequence of repeating applicant data like given below
US
II
CEO
Mr
111111111
0000000111
GuarantorA
111
IN
11111
WILLIAMS1
R3
KENNETH1
City1GU
PA
1934-03-14
[email protected]
GU
R
113 Lazlo LaneCA
Suite 3500CA
OaklandCA
TX
11345
AL
I want to assign a textfield with a value based on the value of coap_flag.
So i need to loop through all the record and check the value of coap_flag and then assign the textfield a value based on that.
I am new to Adobe livecycle...Please help me how it can be done.
I have developed something like this
foreach Item in ($record.applicant[*].coap_flag) do
test.value=Item
if(test.value=="MA")then
concat($record.applicant.first_name,$record.applicant.middle_name)endif
endforUsing the data you posted in the forum, I copied it a couple of times to give multiple records and used this code to extract the different values that you wanted. I had to wrap it in a <root> node that I called root (to make it valid XML). In my case I wrote the extracted values to a field, but in your case you can do whatever you want with them. Note that this was done in javascript:<br /><br />var currentElement;<br />var obj;<br /><br />//Get the nodes below the root node in the dataDom<br />obj = xfa.datasets.data.root.nodes;<br /><br />//Set an initial value for the textField<br />TextField1.rawValue = "The values of the coap_flag are: ";<br /><br />//Loop through the nodes in the obj set <br />for (i=0; i< obj.length ; i++){<br /> //set the currentElement to the 1st child node<br /> currentElement = obj.item(i);<br /> //Check to see if it is an applicant node<br /> if (currentElement.name == "applicant"){<br /> //It is an applican, now find the coap_flag node value and write it to the text field<br /> TextField1.rawValue += "\n" + xfa.resolveNode("xfa.datasets.data.root.applicant[" + i + "]").coap_flag.value;<br /> }<br />}
-
Loop through select and create cursor
Is it possible to create a cursor after looping through a select?
FOR TEST IN
SELECT *
FROM SOMETABLE
WHERE SOMEID > 100
) LOOP
IF TEST.NAME = 'AB' THEN
--CREATE CURSOR AND LOAD DATA
--LOAD TEST.ID, TEST.NAME, TEST.ADATE INTO NEW CURSOR
END IF;
END LOOP; This is just a sample not the actual scenario.SeshuGiri wrote:
Is it possible to create a cursor after looping through a select?Yes. But is also usually the wrong thing to do.
A cursor loop within another cursor loop is known as a nested loop join in SQL. The SQL language is perfectly able to do joins like that. And far better and faster. It has a very clever optimiser and has more sophisticated algorithms than just a nested loop, for joining data sets.
The sample code you've posted shows a very old 80's style Cobol approach to processing ISAM files or magnetic tape. In a row-by-row fashion.
This approach does not scale in the modern database, where the SQL language is a data set processing language - and not an I/O interface for merely reading a record/row and writing a record/row as we did in the 80's with file-based data records.
The basic approach to Oracle is: Maximise SQL. Minimise PL/SQL (Java/etc).
This means using the very flexible, incredibly powerful, SQL language first and foremost to crunch database data. And only when the processing is beyond the capability of the SQL language alone, employ PL/SQL. Else restrict PL/SQL to managing only the process flow and error handling of SQL language statements. -
How to loop through XML data in a table of XMLType?
Hi,
I am failry new to xml document processing in Oracle using PL/SQL.
My DB version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
I have successfully loaded an xml document into a table using the following two statements:
1) CREATE TABLE mytable2 OF XMLType;
2) INSERT INTO mytable2 VALUES (XMLType(bfilename('IMAGE_FILE_LOC', 'IFTDISB20100330172157C002.xml'), nls_charset_id('AL32UTF8')));
Now I need to traverse through the various nodes within the xml document and extract values of elements of each node. The question I have is:
How do I loop through a node? A VALID record is enclosed within the <checkItem> </checkItem> tags.
Here is a snippet of the data in that xml document:
++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="UTF-8"?>
<bdiData>
<documentControlInfo>
<documentInfo>
<docDescription>Check images and data for Test Company, account number 1234567890</docDescription>
<docID>
<ID>20100330172157</ID>
</docID>
<docModifier>Test Company</docModifier>
<docCreateDate>2010-03-30</docCreateDate>
<docCreateTime>17:21:57-0700</docCreateTime>
<standardVersion>1.0</standardVersion>
<testIndicator>0</testIndicator>
<resendIndicator>0</resendIndicator>
</documentInfo>
<sourceInfo>
<sourceName>The Bank IFT</sourceName>
<sourceID>
<idOther>TheBankIFT</idOther>
</sourceID>
</sourceInfo>
<destinationInfo>
<destinationName>Test Company</destinationName>
<destinationID>
<idOther>FEI3592</idOther>
</destinationID>
</destinationInfo>
</documentControlInfo>
<checkItemCollection>
<collectionInfo>
<description>Items</description>
<ID>1269994919135</ID>
<Classification>
<classification>Items</classification>
</Classification>
</collectionInfo>
<checkItemBatch>
<checkItemBatchInfo>
<description>Paid Checks</description>
<ID>1269994919135</ID>
<Classification>
<classification>Paid Checks</classification>
</Classification>
</checkItemBatchInfo>
<checkItem>
<checkItemType>check</checkItemType>
<checkAmount>86468</checkAmount>
<postingInfo>
<date>2010-03-29</date>
<RT>10700543</RT>
<accountNumber>1234567890</accountNumber>
<seqNum>009906631032</seqNum>
<trancode>001051</trancode>
<amount>86468</amount>
<serialNumber>300040647</serialNumber>
</postingInfo>
<totalImageViewsDelivered>2</totalImageViewsDelivered>
<imageView>
<imageIndicator>Actual Item Image Present</imageIndicator>
<imageViewInfo>
<Format>
<Baseline>TIF</Baseline>
</Format>
<Compression>
<Baseline>CCITT</Baseline>
</Compression>
<ViewSide>Front</ViewSide>
<imageViewLocator>
<imageRefKey>201003260000738400851844567205_Front.TIF</imageRefKey>
<imageFileLocator>IFTDISB20100330172157M002.zip</imageFileLocator>
</imageViewLocator>
</imageViewInfo>
<imageViewInfo>
<Format>
<Baseline>TIF</Baseline>
</Format>
<Compression>
<Baseline>CCITT</Baseline>
</Compression>
<ViewSide>Rear</ViewSide>
<imageViewLocator>
<imageRefKey>201003260000738400851844567205_Rear.TIF</imageRefKey>
<imageFileLocator>IFTDISB20100330172157M002.zip</imageFileLocator>
</imageViewLocator>
</imageViewInfo>
</imageView>
</checkItem>
<checkItem>
<checkItemType>check</checkItemType>
<checkAmount>045</checkAmount>
<postingInfo>
<date>2010-03-29</date>
<RT>10700543</RT>
<accountNumber>1234567890</accountNumber>
<seqNum>008518967429</seqNum>
<trancode>001051</trancode>
<amount>045</amount>
<serialNumber>200244935</serialNumber>
</postingInfo>
<totalImageViewsDelivered>2</totalImageViewsDelivered>
<imageView>
<imageIndicator>Actual Item Image Present</imageIndicator>
<imageViewInfo>
<Format>
<Baseline>TIF</Baseline>
</Format>
<Compression>
<Baseline>CCITT</Baseline>
</Compression>
<ViewSide>Front</ViewSide>
<imageViewLocator>
<imageRefKey>201003290000713900851896742901_Front.TIF</imageRefKey>
<imageFileLocator>IFTDISB20100330172157M002.zip</imageFileLocator>
</imageViewLocator>
</imageViewInfo>
<imageViewInfo>
<Format>
<Baseline>TIF</Baseline>
</Format>
<Compression>
<Baseline>CCITT</Baseline>
</Compression>
<ViewSide>Rear</ViewSide>
<imageViewLocator>
<imageRefKey>201003290000713900851896742901_Rear.TIF</imageRefKey>
<imageFileLocator>IFTDISB20100330172157M002.zip</imageFileLocator>
</imageViewLocator>
</imageViewInfo>
</imageView>
</checkItem>
<checkItemBatchSummary>
<totalItemCount>1028</totalItemCount>
<totalBatchAmount>61370501</totalBatchAmount>
<totalBatchImageViewsDelivered>2056</totalBatchImageViewsDelivered>
</checkItemBatchSummary>
</checkItemBatch>
<collectionSummary>
<totalBatchCount>1</totalBatchCount>
<totalItemCount>1028</totalItemCount>
<totalCollectionAmount>61370501</totalCollectionAmount>
<totalCollectionImageViewsDelivered>2056</totalCollectionImageViewsDelivered>
</collectionSummary>
</checkItemCollection>
<documentSummaryInfo>
<totalCollectionCount>1</totalCollectionCount>
<totalBatchCount>1</totalBatchCount>
<totalItemCount>1028</totalItemCount>
<totalDocumentAmount>61370501</totalDocumentAmount>
<totalDocumentImageViewsDelivered>2056</totalDocumentImageViewsDelivered>
</documentSummaryInfo>
</bdiData>
++++++++++++++++++++++++++++++++++++++++++++++++
Any ideas and or suggestions will be greatly appreciated.
Cheers!
Edited by: user12021655 on Aug 3, 2010 1:25 PMI really need to update my blog to get the example you are looking for posted. I did a quick search on the forums for XMLTable and found a good example at {message:id=4325701}. You will want to use OBJECT_VALUE in the PASSING clause where you need to reference the column in your table.
Note: See the FAQ in the upper right for how to use the tag to wrap objects to retain formatting. Also your XML is missing closing nodes. -
Populate Local XML File, and Loop through it
I created a local property of type XML. I want to populate this variable with the results of a SQL query, and store it in local memory. Then later, I will loop through this file and perform actions. Basically I am going to have to loop through this resultset many times, and if I can store it in memory, I won't have to re-qurey the DB>
#1 Is this possible?
Right now, I use a repeater on the SQL, and assign the rowset/rowset/row to the local XML Variable.(Assign XML). SHould I use Assign XML, or APpend XML for the Link Type
THen later I am trying a repeater to loop through the flle, and I have no idea where to point the xpath expression to.
Thanks for the help in advance,
JEffFrom what I understand you are trying to do - Rather than repeating on the SQL query you can link the "Result" of the SQL Query action to the local property (type xml) [and yes you just say Assign XML instead of Append or anything else].
What this would do is assign the local variable the results of the SQL Query in an xMII XML format and then you can further work on this XML.
But rather than using the local variable you can repeat on the SQL Query Action (the way you are doing currently) and manipulate what ever you want to. There is no question of requerying the DB as ur DB would be queried only one time (the SQL Query Action Block will ensure this) and then the repeater would be repeating only on the resulset rendered by the SQL Query action.
Did this make it clearer or have I not understood your problem? -
I am looking for an example of how to loop through an xml structure, preferrably in VBScript, but I will take a Javascript example and try to figure out how to adapt it.
Is a FOR EACH loop possible? In normal VBScript you can do something like this...
‘strQuery = “/ProfilesInfo/Profiles/ProfileInfo/Profile/Fields/Field [Name='ProfileUri' or Name= 'Age'] /(Name|Value)”
Set colNodes = xmlDoc.selectNodes( strQuery )
If colNodes.length>0 Then
For Each objNode in colNodes
Print objNode.nodeName & “: ” & objNode.text
Next
is it possible to do something like this with XML? Maybe something like
For each node in myDocument.XMLElements.Item(1)
{do something}
Next
If there is a better way, and I am sure there is, I'll take an example of that instead.
I am sure there is probably a way to do it with XPath, but I haven't been able to find any examples of using XPath with VBScript.
If anyone has an example of how to use XPath with VBScript I would greatly appreciate it.
Thank youKasyan, thank you for the reply. I looked at that part in the book and I have tried using the example code, but I am having difficulty in understanding how it is being used, maybe you, or someone can help to explain it.
So in an example like this:
Class ProcessChildrenRule
Public Property Get name
name = "ProcessChildrenRule"
End Property
Public Property Get xpath
xpath = "//XMLElement"
End Property
Public Function apply(myXMLElement, myRuleProcessor)
glueCode_processChildren(myRuleProcessor)
With myXMLElement
myXMLElement.XMLattributes.Item(1).Value
myStory.InsertionPoints.Item(-1).Contents =
.XMLAttributes.Item(1).Value & vbCr
End With
apply = false
End Function
End Class
There are 5 things that I am not understanding.
1. How is "xpath" being used? I don't see another occurance of it other than when the variable xpath is set.
2. How is name being used? I don't see another occurance of it other than when the variable name is set.
3. Why is "Public Function apply" created in each class? In the examples in the book, that function exists in each Class. Why not just create the function outside of the class and call it from inside the class?
4. Where is the "apply" function being called from? It doesn't get called from inside or outside the class on the example pages anywhere?
5. Where are the values of myXMLElement and myRuleProcessor being set before they are used in the function?
Even in the examples you gave, once I set the xpath value, what do I do with it after that? How do I write out the value of what I am searching for with the xpath?
So going back to my original question, if I set xpath = "/devices/device", how do I loop through each "device" node and write them out? That is where it is breaking down for me. I haven't seen any examples in the book or in the downloaded example code that show how to do that. -
Oracle Looping through XML nodes
Hi,
I have this XML which i m getting as response from a webservice. i need to loop through nodes and i m not sure how to go about it. i have done example using dbms_xmldom but i m literally stuck. this is the xml here i need to loop through
statuslognotes for one enquiry, there may be multiple statuslognotes and need to insert into database....
i also need to check for multiple updatedenquiry and if thats got statuslognotes....i hope you get me.
<ProcessOperationsResult xmlns="http://www.abc.co.uk/schema/am/connector/webservice" >
<Response SchemaVersion="1.4" xmlns="" >
<OperationResponse>
<GetEnquiryStatusChangesResponse>
<UpdatedEnquiry>
<EnquiryNumber>104</EnquiryNumber>
<ExternalSystemNumber>1</ExternalSystemNumber>
<ExternalSystemReference>195</ExternalSystemReference>
<EnquiryStatusLog>
<EnquiryStatusCode>1224</EnquiryStatusCode>
<EnquiryStatusName>Cancelled By User</EnquiryStatusName>
<AssignedOfficerCode>BBB</AssignedOfficerCode>
<AssignedOfficerName>Testing</AssignedOfficerName>
<LoggedTime>2007-12-11T14:44:53</LoggedTime>
<LogEffectiveTime>2007-12-11T14:44:52</LogEffectiveTime>
<StatusFollowUpTime>2007-12-11T14:44:52</StatusFollowUpTime>
<LoggedByUserName>System Supervisor</LoggedByUserName>
<LoggedByUserId>AAA</LoggedByUserId>
</EnquiryStatusLog>
<EnquiryStatusLog>
<EnquiryStatusCode>1225</EnquiryStatusCode>
<EnquiryStatusName>Cancelled By User</EnquiryStatusName>
<AssignedOfficerCode>DEF</AssignedOfficerCode>
<AssignedOfficerName>Srinivas</AssignedOfficerName>
<LoggedTime>2007-12-11T14:44:53</LoggedTime>
<LogEffectiveTime>2007-12-11T14:44:52</LogEffectiveTime>
<StatusFollowUpTime>2007-12-11T14:44:52</StatusFollowUpTime>
<LoggedByUserName>System Supervisor</LoggedByUserName>
<LoggedByUserId>AAA</LoggedByUserId>
</EnquiryStatusLog>
</UpdatedEnquiry>
<UpdatedEnquiry>
<EnquiryNumber>105</EnquiryNumber>
<ExternalSystemNumber>1</ExternalSystemNumber>
<ExternalSystemReference>196</ExternalSystemReference>
<EnquiryStatusLog>
<EnquiryStatusCode>1226</EnquiryStatusCode>
<EnquiryStatusName>Cancelled By User</EnquiryStatusName>
<AssignedOfficerCode>Test</AssignedOfficerCode>
<AssignedOfficerName>SS</AssignedOfficerName>
<LoggedTime>2007-12-11T14:44:53</LoggedTime>
<LogEffectiveTime>2007-12-11T14:44:52</LogEffectiveTime>
<StatusFollowUpTime>2007-12-11T14:44:52</StatusFollowUpTime>
<LoggedByUserName>System Supervisor</LoggedByUserName>
<LoggedByUserId>BS</LoggedByUserId>
</EnquiryStatusLog>
</UpdatedEnquiry>
</GetEnquiryStatusChangesResponse>
</OperationResponse>
</Response>
</ProcessOperationsResult>
Any help appreciated....as i m new to this XPATH stuff in oracle.
Cheers
Shi,
i have written this stored procedure, but i m sure this is not perfect. i want someone to help me out with this.
CREATE OR REPLACE procedure ParseXML as
l_xml XMLTYPE;
l_value VARCHAR2(10);
SCHEMALIST_DOM DBMS_XMLDOM.DOMDOCUMENT;
SCHEMA_NODELIST DBMS_XMLDOM.DOMNODELIST;
SCHEMA_NODELIST_SUB DBMS_XMLDOM.DOMNODELIST;
SCHEMA_NODE DBMS_XMLDOM.DOMNODE;
SCHEMA_sub_XPATH VARCHAR2(256);
SCHEMA_XPATH VARCHAR2(256);
CHILD_XPATH VARCHAR2(256);
SOURCE_PATH VARCHAR2(256);
XPATH_INDEX number(2);
XPATH_sub_INDEX number(2);
NODE_VALUE VARCHAR2(256);
Statcode VARCHAR2(256);
Statname VARCHAR2(256);
Officer VARCHAR2(256);
BEGIN
l_xml := XMLTYPE.createXML('<ProcessOperationsResult xmlns="http://www.abc.co.uk/schema/am/connector/webservice">
<Response SchemaVersion="1.4" xmlns="">
<OperationResponse>
<GetEnquiryStatusChangesResponse>
<UpdatedEnquiry>
<EnquiryNumber>104</EnquiryNumber>
<ExternalSystemNumber>1</ExternalSystemNumber>
<ExternalSystemReference>195</ExternalSystemReference>
<EnquiryStatusLog>
<EnquiryStatusCode>1224</EnquiryStatusCode>
<EnquiryStatusName>Cancelled By User</EnquiryStatusName>
<AssignedOfficerCode>TEST</AssignedOfficerCode>
<AssignedOfficerName>test</AssignedOfficerName>
<LoggedTime>2007-12-11T14:44:53</LoggedTime>
<LogEffectiveTime>2007-12-11T14:44:52</LogEffectiveTime>
<StatusFollowUpTime>2007-12-11T14:44:52</StatusFollowUpTime>
<LoggedByUserName>System Supervisor</LoggedByUserName>
<LoggedByUserId>BS</LoggedByUserId>
</EnquiryStatusLog>
<EnquiryStatusLog>
<EnquiryStatusCode>1225</EnquiryStatusCode>
<EnquiryStatusName>Cancelled By User</EnquiryStatusName>
<AssignedOfficerCode>DEF</AssignedOfficerCode>
<AssignedOfficerName>SSi</AssignedOfficerName>
<LoggedTime>2007-12-11T14:44:53</LoggedTime>
<LogEffectiveTime>2007-12-11T14:44:52</LogEffectiveTime>
<StatusFollowUpTime>2007-12-11T14:44:52</StatusFollowUpTime>
<LoggedByUserName>System Supervisor</LoggedByUserName>
<LoggedByUserId>SBS</LoggedByUserId>
</EnquiryStatusLog>
</UpdatedEnquiry>
<UpdatedEnquiry>
<EnquiryNumber>105</EnquiryNumber>
<ExternalSystemNumber>1</ExternalSystemNumber>
<ExternalSystemReference>196</ExternalSystemReference>
<EnquiryStatusLog>
<EnquiryStatusCode>1226</EnquiryStatusCode>
<EnquiryStatusName>Cancelled By User</EnquiryStatusName>
<AssignedOfficerCode>TEST</AssignedOfficerCode>
<AssignedOfficerName>test</AssignedOfficerName>
<LoggedTime>2007-12-11T14:44:53</LoggedTime>
<LogEffectiveTime>2007-12-11T14:44:52</LogEffectiveTime>
<StatusFollowUpTime>2007-12-11T14:44:52</StatusFollowUpTime>
<LoggedByUserName>System Supervisor</LoggedByUserName>
<LoggedByUserId>SBS</LoggedByUserId>
</EnquiryStatusLog>
</UpdatedEnquiry>
</GetEnquiryStatusChangesResponse>
</OperationResponse>
</Response>
</ProcessOperationsResult>');
SCHEMALIST_DOM := DBMS_XMLDOM.newDOMDocument(L_XML);
SCHEMA_NODELIST := DBMS_XMLDOM.GETELEMENTSBYTAGNAME(SCHEMALIST_DOM,'GetEnquiryStatusChangesResponse');
SCHEMA_NODELIST_SUB := DBMS_XMLDOM.GETELEMENTSBYTAGNAME(SCHEMALIST_DOM,'/UpdatedEnquiry/EnquiryStatusLog');
FOR i in 0 .. (DBMS_XMLDOM.GETLENGTH(SCHEMA_NODELIST) - 1) LOOP
XPATH_INDEX := i+1;
FOR j in 0 .. (DBMS_XMLDOM.GETLENGTH(SCHEMA_NODELIST_SUB) - 1) LOOP
XPATH_SUB_INDEX := J+1;
SCHEMA_SUB_XPATH := '/GetEnquiryStatusChangesResponse/UpdatedEnquiry[' || XPATH_INDEX || ']/EnquiryStatusLog[' || XPATH_sub_INDEX || ']/';
--dbms_output.put_line(SCHEMA_SUB_XPATH);
CHILD_XPATH := SCHEMA_SUB_XPATH || 'EnquiryStatusCode/text()';
dbms_output.put_line('child path text ' || child_XPATH);
DBMS_XSLPROCESSOR.VALUEOF(DBMS_XMLDOM.MAKENODE(SCHEMALIST_DOM),CHILD_XPATH, Statcode);
CHILD_XPATH := SCHEMA_SUB_XPATH || 'EnquiryStatusName/text()';
DBMS_XSLPROCESSOR.VALUEOF(DBMS_XMLDOM.MAKENODE(SCHEMALIST_DOM),CHILD_XPATH, Statname);
CHILD_XPATH := SCHEMA_SUB_XPATH || 'AssignedOfficerCode/text()';
DBMS_XSLPROCESSOR.VALUEOF(DBMS_XMLDOM.MAKENODE(SCHEMALIST_DOM),CHILD_XPATH, Officer);
dbms_output.put_line('EnquiryStatusCode => "' || Statcode || '",');
dbms_output.put_line('EnquiryStatusname => "' || Statname || '",');
dbms_output.put_line('AssignedOfficerCode => "' || Officer || '",');
end loop;
--GetEnquiryStatusChangesResponse/UpdatedEnquiry[2]
schema_xpath := '/GetEnquiryStatusChangesResponse/UpdatedEnquiry[' || XPATH_INDEX || ']/EnquiryStatusLog['|| XPATH_INDEX || ']/' ;
CHILD_XPATH := SCHEMA_XPATH || 'EnquiryStatusCode/text()';
dbms_output.put_line('another node text ' || child_XPATH);
DBMS_XSLPROCESSOR.VALUEOF(DBMS_XMLDOM.MAKENODE(SCHEMALIST_DOM),CHILD_XPATH, Statcode);
end loop;
end;
Basically i may just get one UpdatedEnquiry record with multiple EnquiryStatusLog (changes),
I need to get the EnquiryStatusLog nodes and create a insert stmt with the Enquiry Number.
and if theres multiple <UpdatedEnquiry> nodes, i need the same thing done.
Hope i make sense here.....
Can someone help
Cheers
S -
I got this really great script that loops through some XML files and does stuff based off the content.
What I would like to do now is have it repeat when it gets to a certain field. for example my xml file would look like this.
<xml>
<fileName>nameoffile</fileName>
<userEmail>[email protected]</userEmail>
<commandList>
<item>info here</item>
<item>more info here</item>
<item>yet more info</item>
<item>still more info here</item>
</commandList>
</xml>
then basically i need the applescript to see the <commandList> tag and then repeat for each item.
i can't seem to wrap my head around how to get it to happen.
currently I am using this to extract the normal tags from the xml file
set theXML to choose file
tell application "System Events"
tell XML element 1 of contents of XML file theXML
set the fileName to value of (XML elements whose name is "fileName")
... and so on
end tell
end tell
i believe i have to put an if statment in saying that if the element name == "commandList" then
repeat with item in commandList
my stuff here.
end repeat
but i'm not sure how to build the statement.
thanks for any help.
PSomething like this?
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="this text can be pasted into the Script Editor">
set theXML to POSIX path of (choose file)
tell application "System Events"
tell XML element 1 of contents of XML file theXML -- root element
set the fileName to value of XML element "fileName"
get value of XML elements of XML element "commandList" -- sub elements
repeat with anItem in the result
log anItem
end repeat
end tell
end tell
</pre> -
Loop through a csv file and return the number of rows in it?
What would be simplest way to loop through a csv file and
return the number of rows in it?
<cffile action="read" file="#filename#" output="#csvstr#"
>
<LOOP THROUGH AND COUNT ROWS>ListLen(). Use chr(13) as your delimiter
-
How to loop through xml records from file without ROW , /ROW tags?
I am using dbms_XMLSave.insertXML procedure to insert xml formated record from file. MY xmlformated records does not have open and close ROW tags. I have multiple records in the file.How can I loop through without <ROW>,</ROW> tags?
I am using dbms_XMLSave.insertXML procedure to insert xml formated record from file. MY xmlformated records does not have open and close ROW tags. I have multiple records in the file.How can I loop through without <ROW>,</ROW> tags?
-
How to loop through many XML messages and parse them ?
Hi All
I have been trying very hard to loop through many XML messages and process each of them. Let me first explain the problem -
Suppose I have the following String -
<xyz>
<abc>happy</abc>
</xyz>
<xyz>
<abc>new</abc>
<xyz>
<xyz>
<abc>year</abc>
</xyz>
I have to process each message within the <xyz></xyz> tag and find the falue of <abc> element (happy, new and year).
The extraction of <abc> value is very simple, I am using SAX parser's startElement() method to check every element's name and if the element's name is <abc> pick up the value. But I am not able to loop through the different messages within the <xyz></xyz> tag.
I am thinking of using another DOM parser -
DOMParser domParser = new DOMParser();
StringReader rdr = new StringReader(inputXML);
InputSource src = new InputSource(rdr);
domParser.parse(src);
Document doc = domParser.getDocument();
NodeList nodeList = doc.getElementsByTagName("xyz");
Now I can loop through this nodeList, but not able to. Is using the DOM parser and NodeList the preferable way of lopping through the messages, then how I can loop through ? Or is there any other way ?
I have been trying on this for quite a few days, but not able to. Can you please help me out ?
Thanking you in advance ....
Nirmalya SinhaHi,
Try using the SAX reader from the dom4j package. The document object that you receive contains methods for getting the root elements and with that you can traverse down to the sub elements of it.
Hope this was of some help. -
Loop through table(table is created dynamically)
Hi all,
I have a table that is created dynamically.It has got 3 columns and 8 rows.In first row - first column,I have a value that is set dynamically.Now, How can I loop through this table and get this value?
The table context node and value attributes are also created dynamically.
Table node is "TimesheetData" and value attribute is col1.Value,col1.Value and col3.Value
TimesheetData
col1.Value
col2.Value
col3.Value
Again.... this node and attributes are not there in my view context by default, its getting created and binded dynamically here.
Thanks KukkuHi,
Following is the code to iterate through the elements
//Table node is "TimesheetData" and value attribute is col1.Value,col1.Value and col3.Value
for(int x=0;x<wdContext.getChildNode("TimesheetData",0).size(); x++)
IWDNodeElement nodeElement = wdContext.nodeTimesheetData().getElementAt(x);
String value1 = (String) nodeElement.getAttributeValue("col1");
String value2 = (String) nodeElement.getAttributeValue("col2");
String value3 = (String) nodeElement.getAttributeValue("col3");
Regards
Ayyapparaj -
Looping through records in XML Variable !!
Hi,
I am getting no way how to do this. I am getting the below XML from a custom DSC component. Now I need to process it.
<root>
<records total_records="4">
<record>
<jobno>1122</jobno>
<cust_name>Abhinav</cust_name>
<email>[email protected]</email>
<stat>1</stat>
</record>
<record>
<jobno>2233</jobno>
<cust_name>Doctor Dhober</cust_name>
<email>[email protected]</email>
<stat>0</stat>
</record>
<record>
<jobno>4666</jobno>
<cust_name>Vinau Dubey</cust_name>
<email>[email protected]</email>
<stat>1</stat>
</record>
<record>
<jobno>7677</jobno>
<cust_name>Nelesh Poda</cust_name>
<email>[email protected]</email>
<stat>0</stat>
</record>
</records>
</root>
Now I need to loop through every record & do some stuff for each one. In my process I have to send a mail to each of the user in the XML file. I tried it using SET VALUE's Node Set Functions, but not successful. Any help.
Thanks.
AbhinavYour xpath doesn't match your XML - you are missing the root node in your xpath expression:
Expression: /process_data/myXML/records/record[1]/email
should be:
/process_data/myXML/root/records/record[1]/email
When you build your loop there is one other thing to be careful of. If you evaluate an xpath variable inside of another xpath expression, it gets inserted as a string. This happens even if the variable is an integer. For example: If I have an integer variable counter which is set to 3 and evaluate:
/process_data/myXML/root/records/record[/process_data/@counter]/email The xpath expression will insert "3" (a string) and not an integer as you would expect. The result will not be the third node. This can be a source of frustration and its hard to debug.
Instead, use the number function inside the expression:
/process_data/myXML/root/records/record[number(/process_data/@counter)]/email
I've attached a sample process that shows this.
Maybe you are looking for
-
I don't mind that Muse does this upon uploading my website, but once my text becomes an image on my site, it creates a light halo around my text making it fuzzy. Is there a way to prevent Muse from changing my text into images?
-
How to install Nokia Suite on other partition tha...
I would like to install Nokia Suite on to another disk-partition because my C-disk is almost full. With the installer I cannot choose. Anyone a solution? Thanks in advance. Van Solved! Go to Solution.
-
SystemManager.as : 'should never get here' when uploading multiple files
I have a code for uploading multiple files. The code works so that when complete event from the first upload is received, the second upload is started. The code works fine on Flash Player 9, but now when I changed my compiler settings to require vers
-
hi all i am bw cunsultant and now i am coming into SEM bcs-bps can someone help me out how should i start to learn. if someone has the documnets please send to me [email protected] i shall then very thank full for you
-
Oracle froms and jre1.6
Hello, Can anyone tell if suns jre1.6.0_14 is certified for the oracle forms applications 10.1.2.3? I found out that jre1.6.0_04 is certified but are the later release of jre1.6.0_xx also certified? thx in advance.