Help: to get XML child data in faster way?
Dear all,
With the following xml file, how can I use xslt by Java to get any <data> child element's string content. For example, to get "ee ff gg hh" in <Data name="inputs2">ee ff gg hh</Data> [this is in <Info Date="03-05-2003"> branch]?
I want to get it in a quick way, so I do not want to get it by DOM. The question is what is the best way to get it in Java? Is it possible by SAX combined with XSLT (XPATH) - with Java Code?
<?xml version="1.0" encoding="UTF-8"?>
<Customer>
<Infos>
<Info Date="03-05-2003" >
<Inputs name="John">
<Data name="inputs1">a b c d</Data>
<Data name="inputs2">aa bb cc dd</Data>
<Data name="inputsn">an bn cn dn</Data>
</Inputs>
</Info>
<Info Date="03-05-2003" >
<Inputs name="Mike">
<Data name="inputs1">e f g h</Data>
<Data name="inputs2">ee ff gg hh</Data>
<Data name="inputsn">en fn gn hn</Data>
</Inputs>
</Info>
</Infos>
</Customer>Thanks
- John
The problem is my file could be very large in size,
and if "load the whole thing into memory", it will
throw out of memory exception. So the best thing would
be dynamically load it if possible.
SAX and XSLT actually can do some help, since whenever
it finds my requested node, it can stop processing -
but the problem here is: it has to reparse the XML
file from the beginning every time to find the
requested node - a very time-consuming job...
Any better solution?how about using sax to parse the file, and temporarily insert the records into a DB? You could then use SQL to do your queries.
parsing/inserting might take awhile; but a properly tuned DB (and the java.sql.statement.addBatch()) will minimize this - probably down to the order of a DOM parse.
Other solutions:
- regex and perl/python on the XML file
- splitting the big XML file into little XML files (one file per <Inputs> tag maybe?) and dealing with an individual node at a time
- parsing the file as SAX and caching the info you need (i.e. parse it once and cache the values); then look them up afterwards
Similar Messages
-
After tweak bunch of times the argument inside "Get XML Document Data" I´m still not able to obtain a no null value. Could someone help me to find out what i´m doing wrong?
<?xml version="1.0" encoding="UTF-8"?>
<Holidays>
<Holiday>Date=1/2/2013</Holiday>
<Holiday>Date=1/2/2013</Holiday>
<Holiday>Date=8/4/2013</Holiday>
<Holiday>Date=9/4/2013</Holiday>
<Holiday>Date=1/5/2013</Holiday>
<Holiday>Date=17/5/2013</Holiday>
<Holiday>Date=27/5/2013</Holiday>
<Holiday>Date=6/6/2013</Holiday>
<Holiday>Date=23/6/2013</Holiday>
<Holiday>Date=6/4/2013</Holiday>
<Holiday>Date=25/12/2013</Holiday>
<Holiday>Date=26/12/2013</Holiday>
</Holidays>
Xpath:
"/descendant::Holidays/child::Holiday[attribute::symbol='DateString']/child::LAST"
thank in advance.Hi,
The script first obtain today´s date in this format 1/2/2013 and stores in DateString variable. Then create a XML document based on this:
<?xml version="1.0" encoding="UTF-8"?>
Date=1/2/2013
Date=1/2/2013
Date=8/4/2013
Date=9/4/2013
Date=1/5/2013
Date=17/5/2013
Date=27/5/2013
Date=6/6/2013
Date=23/6/2013
Date=6/4/2013
Date=25/12/2013
Date=26/12/2013
that i´ve upload to uccx. it uses get XML Document Data function and stores the result in DataResult variable.
if
DataResult == null meets True it makes a call redirect to an extension
if false that means "1/2/2013" was found inside the XML archive and sends to another extension.
The problem i see through reactive debug is that always return null,
In brief: I do not know how to tell using the function "find 1/2/2013 inside Holidays.xml document"
this is what I putted inside get XML Document Data function:
"/descendant::Holidays/child::Holiday[attribute::symbol='DateString']/child::LAST" -
UCCX XPath on Get XML Document Data Step always returns null
Hello,
Can someone tell whats wrong with my XPath, because it always returns null. I have tried different variations and nothing. I'm using UCCX 7.0
XML
<?xml version="1.0" encoding="utf-8" ?>
<GetManagersResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.labdomain.com/">
<ClaimManagersList>
<X_CLAIM_MANAGER>
<ClaimManagerUserName>test</ClaimManagerUserName>
</X_CLAIM_MANAGER>
</ClaimManagersList>
</GetManagersResult>
XPATH
"/descendant::GetManagersResult/child::ClaimManagersList/child::X_CLAIM_MANAGER/child::ClaimManagerUserName"
During debug, this is the value of the xml document when it reaches the Get XML Document Data step:
TEXT[<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<GetManagersResult xmlns=\"http://www.labdomain.com/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <ClaimManagersList>\r\n <X_CLAIM_MANAGER>\r\n <ClaimManagerUserName>test</ClaimManagerUserName>\r\n </X_CLAIM_MANAGER>\r\n </ClaimManagersList>\r\n</GetManagersResult>]It's your XML namespace in the root element.
First off, I have never seen the CRS Editor play nice when XML namespaces are involved.
Secondly, with your namespace in place, not even a generic xpath expression tester can find your data. See attachements.
I think that if you find a way to either: not send, or remove the namespace from your document, your xpath expression will work.
With Namespaces
Without Namespaces -
Xpath and Get XML Document Data
Good Morning,
I have just recently gotten involved in a project that requires communicating with some web services (axis2). We have existing scripts that handle this already, but they were built when we weren't on axis2 so now the XML output from the web service call is slightly different and i am no longer able to use the same xpath statement in the Get XML Document Data step.
I am receiving either null values or a prefix namespace error. I am new to xpath and have been reading as best i can from http://www.w3schools.com/xpath/ to try and understand how to write my statements to pull out the data i want correctly.
I have read that sometimes the editor has problems if the XML contains namespace declarations, etc.
Below is an example XML output where I'd like to be able to read the value in the ax211:success. My xpath gets prefix namespace errors as it doesn't recognize ax211.
Xpath: /descendant::ns:validateCertificationResponse/child::ns:return/child::ax211:success
Perhaps my xpath statement is just incorrect and wouldn't retrieve what i expect it to....
Any advice is appreciated.
Thanks,
KevinHi,
well, it appears that text() is automatically appended to the XPath query for some reason in UCCX, this is why you actually see the text node within the ax211:success element. This //*[local-name()="success"] select the whole node, not its first child (which is actually the first element, which also happens to be a text).
Anyway,
// - anywhere
* - any node
And within this "everything" you actually search with the condition within the angular brackets.
G. -
UCCX GET XML Document data - how to force language path
Hi,
I saw that with UCCX, If the trigger have is language FR_CA, when I will use the Get XML Document Data (docTemp, etc,etc )
It will get the value of the file located in the path of FR_CA in the document management.
Lets say, If the trigger language is FR_CA, Is there any way I can use the GET XML Document to open a file in the EN_CA in the document management ?
How can I do that ?
ps : The upload document have this function, we can force a language but I have no idea how to handle this with the Get XML Document.
ThanksI will attach a screenshot of how you can specify the language folder that the Document lives in, regardless of the language of the Trigger or Contact.
Notice that in the variable I am simply referencing the Document filename. This will assume the language of the Contact.
But also notice that within the step, I am saying that the Source document should be found in the L[en_CA] language folder. This does not change the language of the Contact; it simply tells the system to look in a different folder for the file.
Of course, if your Document is not language specific, you could always put it in the Default language folder and then it will be available to all Contacts regardless of Language setting.
Anthony Holloway
Please use the star ratings to help drive great content to the top of searches. -
How to check empty return from Get XML Document Data?
If Get XML Document Data doesn't return a result, how do you test it? String.isEmpty() doesn't do the trick, it still throws the exception "java.lang.NullPointerException". I can't seem to be able to match that up to a cisco exception with a "On Exception Goto" step (which I put right before the XML Document Data step). Any clues anyone?
Hi,
Try this:
variable=Get XML Document Data ()
if(variable == null) then
true
false
Gabriel. -
Cisco UCCX 10.6 Get XML Document Data XPath count() function
Hi
I'd like to retrieve the number of XML nodes in a document to make a script more efficient.
e.g. with this XML, I'd like to know how many <message> nodes there are:
<messages>
<message>contentA</message>
<message>contentA</message>
<message>contentA</message>
</messages>
I've tried iNodeCount = Get XML Document Data (inputXMLfile, "count(//messages/message)")
If I try this in an XPath expression tester then I get the result I'm expecting - an integer of 3. However, in UCCX this produces the error "Can not convert #NUMBER to a NodeList!"... What am I doing wrong?
ThanksHi,
you may want to use a Set or a Do step to execute Java code.
First, reference the XML file (within the repository) by calling DOC[myFile.xml] and of course, assigning this value to a Document type variable, e.g.:
Set myDocument = DOC[myFile.xml]
Then add a Do step that actually does the XPath part of the job.
There's a nice step by step explanation of it here: http://viralpatel.net/blogs/java-xml-xpath-tutorial-parse-xml/
Remember, you can get the Inputstream object of the myDocument variable using the getInputStream() method on it.
G. -
Get XML Document Data step always returns NULL
Hi All,
I was hoping someone might be able to help with this.
I'm writing a holiday script, it uses XML to check whether the date is a holiday or halfday. XML below
<?xml version="1.0" encoding="ISO-8859-1"?>
<Holidays>
<Holiday Date="1/1/2012">Holiday</Holiday>
<Holiday Date="3/1/2012">Halfday</Holiday>
<Holiday Date="6/1/2012">Holiday</Holiday>
<Holiday Date="5/4/2012">Halfday</Holiday>
<Holiday Date="6/4/2012">Holiday</Holiday>
<Holiday Date="8/4/2012">Holiday</Holiday>
<Holiday Date="9/4/2012">Holiday</Holiday>
<Holiday Date="30/4/2012">Halfday</Holiday>
<Holiday Date="1/5/2012">Holiday</Holiday>
<Holiday Date="17/5/2012">Holiday</Holiday>
<Holiday Date="27/5/2012">Holiday</Holiday>
<Holiday Date="6/6/2012">Holiday</Holiday>
<Holiday Date="23/6/2012">Holiday</Holiday>
<Holiday Date="6/4/2012">Holiday</Holiday>
<Holiday Date="3/11/2012">Halfday</Holiday>
<Holiday Date="25/12/2012">Holiday</Holiday>
<Holiday Date="26/12/2012">Holiday</Holiday>
<Holiday Date="19/10/2012">Halfday</Holiday>
</Holidays>
However when I debug the script the result of the Get XML Document step always returns null.
Xpath work great in notepad++
My code is attached, anyone with any pointers?
Regards,
AndyYour XPATH of:
"/Holidays/Holiday[@Date='+DateString+']"
Needs to be:
"/Holidays/Holiday[@Date='"+DateString+"']"
Good luck and happy scripting!
Anthony Holloway
Please use the star ratings to help drive great content to the top of searches. -
Getting parent-child data from a single column in a table
Hi,
I have a parent-child data in a column.
Eg:
0
00
01
010
011
1
10
11
These values are present in the single column itself. My need is to get the parent values for the given child value.
For eg: If I am giving the input as 011, the query should return all its parents, i.e. 01 and 0
Could you please give me any inputs on this?
Thanks,
GVFrank Kulash wrote:
Assuming that each child's id is formed by adding exactly one character to the end of its parent's id:
SELECT id
FROM table_x
START WITH id = :target_id
CONNECT BY PRIOR id LIKE id || '_';
Small tweak to yours Frank if it's just the parents that need identifying...
SQL> ed
Wrote file afiedt.buf
1 with t as (select '0' as x from dual union all
2 select '00' from dual union all
3 select '01' from dual union all
4 select '010' from dual union all
5 select '011' from dual union all
6 select '1' from dual union all
7 select '10' from dual union all
8 select '11' from dual)
9 -- end of test data
10 SELECT x
11 FROM t, (select '&required' as req from dual) req
12 WHERE x != req.req
13 START WITH x = req.req
14* CONNECT BY PRIOR x LIKE x || '_'
SQL> /
Enter value for required: 011
old 11: FROM t, (select '&required' as req from dual) req
new 11: FROM t, (select '011' as req from dual) req
X
01
0
SQL> /
Enter value for required: 11
old 11: FROM t, (select '&required' as req from dual) req
new 11: FROM t, (select '11' as req from dual) req
X
1
SQL> -
Need help in getting process form data
Hi,
We have one IT resource type definition say SSH. We have number of IT resources-abc,xyz of same type-SSH .
When user gets provisioned to this resource, then in the resource profile, we can see resource name as SSH. In the process form of SSH we can see the IT resource name -abc,xyz
Now the requirement is I need this IT resource name from process forom of SSH. I have written one java code which sends out an email to application owner when this SSH resource is revoked. But I need to show the IT resource name-abc,xyz in the email to application owners.
Can anybody help to get the process form data?
Thanks,
Kalpana.yes, add new attribute to the process form and populate using adapter find below code
public long getITResource(String itResource) {
long returnValue = 0;
String methodName = "getITResource";
try {
tcITResourceInstanceOperationsIntf tcITResourceIntf = (tcITResourceInstanceOperationsIntf)Platform.getService(tcITResourceInstanceOperationsIntf.class);
HashMap<String, String> map = new HashMap<String, String>();
map.put("IT Resources.Name", itResource);
tcResultSet resultSet = tcITResourceIntf
.findITResourceInstances(map);
if (resultSet.getRowCount() <= 0) {
logger.error(className, methodName,
"Following IT Resource not fetched:" + map);
throw new Exception("IT Resource not fetched");
resultSet.goToRow(0);
logger.info(className, methodName, "ITResource determined.");
// Got the result
returnValue = resultSet.getLongValue("IT Resources.Key");
tcITResourceIntf.close();
ops.closeUtilityObject();
return returnValue;
} catch (Exception e) {
logger.error(className, methodName, e.getMessage());
return returnValue;
pass itResource name as literal in adapter. If it is 10g use tcUtilityFactory instead of Platforml.getService
--nayan -
How to get xml Element , data and its Childs
hi,
I am trying to get entire Element and its childs depending on condition.
suppose
if(doc.element.name== "despatch"){
// here i want entire despatch element with data and childs and copy into one string like
// eg: String dsp = <despatch><name>body1</name> <value>value1<value>
</despatch>
<?xml version="1.0">
<handler>
<name>header1</name>
<value>value1</value>
</handler>
<despatch>
<name>body1</name>
<value>value1<value>
</despatch>
<gov>
<name>env</name>
<value>value1</value>
</gov>I managed to get number of elements depending on the Element name but i need to get the entire block.
nodeList = document.getElementsByTagName("despatch").item(0).getChildNodes();
for(int i=0;i<nodeList.getLength();i++){
System.out.println("i :"+document.getElementsByTagName("m:Security").item(i));
}any kind of help is appreciated.
Han.
Edited by: HANRAM on Apr 24, 2008 2:48 AMHi Kartik,
This one is similar to my question to print and email invoice at same time. I pass itcpo-tdgetotf = 'X' in order to get otfdata and send email with the attachment of otfdata.
Now I have data in otfdata, but when I call print_otf function, I clear out itcpo-tdgetotf, and passed
itcpo-tddest = device_type but I still get error message said 'Handler not valid for open spool request'.
Can you give me a working example that you have otfdata table and print data from that table. I also post my question on other thread
submit report and export to memory
thanks -
Dear Indesign scripters,
This script is making from all the XML tags ParagraphStyles.
But it refuses to take the child elements. Do I have to use XPath expression? And how?
function main() {
var xes, n, doc, ps, xe;
if ( !app.documents.length ) return;
doc = app.activeDocument;
xes = doc.xmlElements[0].xmlElements;
n = xes.length;
while ( n-- ) {
xe = xes[n];
st = doc.paragraphStyles.itemByName (xe.markupTag.name );
!st.isValid && doc.paragraphStyles.add({name:xe.markupTag.name});
main();
The XML
<Workbook>
<Element_A_01>
<Element_A_01></Element_A_01>
</Element_A_01>
<Element_B_02>
<Element_B_02></Element_B_02>
</Element_B_02>
</Workbook>
Greetings from HollandThe code creates two paragraph styles namely Element_A_01 and Element_B_02. These two are created for the immediate child nodes of the Workbook node. Now it seems that you are trying to create pstyles for all the nodes in the XML, which in your case would still be these two as Element_A_01 has a child node that is also named Element_A_01 and the same is the case for Element_B_02.
If i get your point right then you need to create 4 pstyles if all the nodes have different names, but that is not working. For this you will have to recursively traverse each node that you get from the code xes[n].
The code be something like this
function main() {
var xes, n, doc, ps, xe;
if ( !app.documents.length ) return;
doc = app.activeDocument;
xes = doc.xmlElements[0].xmlElements; //This gives the immediate child nodes of the Workbook node, hence the length in the next statement is 2
n = xes.length;
while ( n-- ) {
xe = xes[n]; //Here you need to recursively traverse the node xe
//The no of child elements of xe can be obtained as xe.xmlElements.length
//First element can be obtained by xe.xmlElements[0]
main();
Hope this solves the issue -
How to get the child data in MDX query?
I have an MDX query that will return the data for an OLAP report. These report data include the parent_id, child_id and some dimensions data in it. How do I modify the MDX query to have a New member to show a dimension value of the child_id.
The child_is is actually the parent_id on another row. It is the "Pstpd Decision" I want to be included in a new column using the "Appeal Id". Thanks
WITH MEMBER [Measures].[Avg TA Time] AS [Measures].[Turn Around Time]/[Measures].[Number of Request]
SELECT NON EMPTY { [Measures].[Number of Request] } ON COLUMNS,
NON EMPTY { ([Request Date Time].[FY-AP].[Account Period].ALLMEMBERS *
[Request Drugs].[Drug Generic Name].[Drug Generic Name].ALLMEMBERS *
[Dispensary].[Dispensary Hierarchy].[Dispensary].ALLMEMBERS *
[Disease].[Tumour Group Site].[Tumour Group Site].ALLMEMBERS *
[Disease].[Tumour Group Sub Site].[Tumour Group Sub Site].ALLMEMBERS *
[Patient].[Patient Agency ID].[Patient Agency ID].ALLMEMBERS *
[Pstpd Decision].[Decision].[Decision].ALLMEMBERS *
[Request].[Request Id Key].[Request Id Key].ALLMEMBERS *
[Request].[Appeal Id].[Appeal Id].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( { [Appeal Yes No].[Status].&[Yes] } ) ON COLUMNS
FROM ( SELECT ( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED) ) ON COLUMNS
FROM [CAP Request])) WHERE ( IIF( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED).Count = 1, STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED), [Request Date Time].[Fiscal Year].currentmember ), [Appeal Yes No].[Status].&[Yes] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
data.
KahluaI got it to work by adding the child_id's "decison' to the fact table as it is alot easier to get that data using Sql Script while creating the fact table and also there is already a "decsion" dimension setup. In the cube I can select the
parent_id's decision and/or child_id's decision. It is working on the report. Thanks.
Kahlua -
In AS2 you could use numChildren to get the number of
children in a given XML file, whats the equivalent in AS3? Ive
tried using var myNum:Number = myXMLname.numChildren , but when I
trace it I just get 0.
ThanksYou need to call a method these days:
Say you have an XML Object like the following:
var myXMLExample:XML =
<EXAMPLE>
<ITEM>
<FRUIT>Apple</FRUIT>
</ITEM>
<ITEM>
<FRUIT>Kiwi</FRUIT>
</ITEM>
<ITEM>
<ANIMAL>Fruitbat</ANIMAL>
</ITEM>
</EXAMPLE>
trace(myXMLExample.ITEM.length()); //since there are three
ITEMS
trace(myXMLExample.ITEM.FRUIT.length()); //since there are
only two ITEMS with FRUIT
//first trace gives you: 3
//second trace gives you: 2 -
Getting parent-child data into an Oracle level-based OLAP hierarchy
We have some organisational data which we need to represent in an Oracle OLAP 10g dimension, preferably populated using Warehouse Builder.
The organisational hierarchy is listed as parent-child pairs, and is both ragged (unbalanced) and skip-level (noncovering). This would lend itself to a value-based hierarchy, but our client would rather we use ROLAP rather than MOLAP, i.e. avoid the use of an Analytical Workspace, which rules out the use of a value-based hierarchy.
Is there a straightforward way to populate a level-based hierarchy using parent-child pair data, and if so how can it be done?
Pointers to tutorials would be welcome, especially if they use Warehouse Builder.If you have an Oracle DB have a look on the CONNECT BY PRIOR functionality.
regards
John
http://obiee101.blogspot.com
Maybe you are looking for
-
FI: Open Items and Disputes
Hi Experts, I would like to know how to retrieve the FI Open items. Basically the SAP tables and criteria to fetch all Open Items. Also, how to identify the disputes in the items. Best Regards, Kurtt
-
ORA-03147 error while running Alert
I am getting "ORA-03147: Missing mandatory TTC field" error while running an alert. I can share error screenshot and the alert query, if needed. (not putting right now as the query is huge) Please note that alert query runs perfectly fine in PLSQL De
-
I have iBook G4 running OS 10.4.11 and I have some files from my cache that will not delete. I have tried using OnyX, secure empty of trash, and option empty trash but nothing works. The files say they are in use. How do I dump these files? Is there
-
Trying to transfer photos from my ipad to my laptop. iphoto imported them. Now I want to disconnect my ipad from the laptop and cannot find an "eject" button or link. Do I just disconnect it? Don't want to lose photos in the process.
-
Create a watchpoint for object attribute
Hi experts, Does anyone know how to create a watchpoint for object attribute in the debug module? I've already created watchpoint for variables, but I don't manage to create for attributes, like -ATTRIBUTE_REF. I put -ATTRIBUTE_REF and the watchpoint