How to get only direct child node by tag name
Hi,
I am using the method
getElementsByTagName("")....
This works except the problem is my XML schema/file has some recursive tags,
I have a <question> element which can have an <answer> or another <question>.
When parsing the XML file I want to be able to get a list of sub questions for a given question, but only if it is a direct child of that question.
So if i have:
<question>
<text>q1</text>
<question>
<text>q2</text>
<question>
<text>q3</text>
</question>
</question>
</question>If I'm dealing with the "q1" question I want only "q2" but not "q3". Whereas getElementsByTagName will take both q2 and q3. How can I achieve this.
Thanks
You want only children and not other descendants? Then getChildNodes() and getFirstChild() and methods with similar names look like a good start.
Similar Messages
-
XPath - How to get only second matching node?
Hello,
withs this XPath expression:
//td[contains(@name, 'FirstColumn')]on this XML:
<html>
<table>
<tr>
<td name="MyFirstColumnInRow">A11 - skip me!</td>
<td name="MySecondColumnInRow">A12</td>
</tr>
<tr>
<td name="MyFirstColumnInRow">A21 - find me!</td>
<td name="MySecondColumnInRow">A22</td>
</tr>
<tr>
<td name="MyFirstColumnInRow">A31 - skip me!</td>
<td name="MySecondColumnInRow">A32</td>
</tr>
</table>
</html>I have got three matching nodes: A11, A21, A31 .
How to expand this XPath expression to get only the second node: A21 ?
I can't find appropriate solution.
Thanks in advance.Why don't you get all the nodes and than you can do whatever you want? You can even get an iterator (here commented out) or write your rule in a loop.
public static Document parseXmlIntoDOM(File xmlFile,boolean validating,boolean spaceAware) throws XMLException{
Document document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(spaceAware);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(xmlFile);
catch (SAXException sxe) {throw new XMLException("An error in parsing the input source",sxe);}
catch (ParserConfigurationException pce) {throw new XMLException("An error in parsing the input source",pce);}
catch (IOException ioe) {throw new XMLException("An error in parsing the input source",ioe);}
return document;
public static void main(String args[]){
Document dom;
try{
File file = new File("C:\\Documents and Settings\\diego\\xml\\newXMLDocument.xml");
dom = parseXmlIntoDOM(file,false,true);
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "/html/table/tr/td";
DTMNodeList tdNodes = (DTMNodeList)xpath.evaluate(expression, dom, XPathConstants.NODESET);
//DTMIterator iterator=tdNodes.getDTMIterator();
Node secondinstance = tdNodes.item(2);
System.out.println(secondinstance.getTextContent());
}catch(Exception e){
e.printStackTrace();
}This works just fine for me and that is my output (in the standard):
compile:
run:
A21 - find me!
BUILD SUCCESSFUL (total time: 1 second)Sorry the code I wrote is awful, but working. P.S. is there a way for not using the "DTM" api? -
How to get only the graphics path without graphics names?
Hi All,
I need to get only the graphics path without graphics names like 'd:\Images\' instead of 'd:\Images\abc.jpg' in JS.
Thanks,
PraveenSomething like this should get you close…
#target indesign
function main() {
if (app.documents.length == 0) {
alert('Please have an "Indesign" document before running this script.');
return;
docRef = app.activeDocument;
with(docRef) {
var x = rectangles[0].allGraphics[0].itemLink.filePath;
var y = new File(x).parent.fsName;
$.writeln(y);
main(); -
How to get only direct reporting person under MSS
Hi All,
We have got a requirement to Display direct reporting under MSS in EP.
According to standard SAP functionality there could be only one manager in an orgunit(Chief) and if we need other managers under that we need to create a sub orgunit and make that manager as Chief.
In Standard functionality it only shows all the employees under that Chief, and shows nothing for other managers in the same org unit.
Our requirement is that it should show only the direct reporting empoyees irrespetive of Chief in the same orgunit.
for the purpose system uses two rules: MSS_TMV_RULE1, MSS_TMV_RULE5.
In these rules two evaluation paths are being used SAP_MANG, MSSDIREC.
I created custom evaluation paths, but it's not working.
Could any of you suggest how to solve this.
thanks & regards,
AnuraagHello Anurag,
We are also implementing MSS without chief positions ....were you able to fix your issue ...please help if you can.... -
XML parsing - NodeList : how to get only the desired childs
Hi
my question is about parsing XML files. I use "getChildNodes()" method (from org.w3c.dom.Node class) to get in a NodeList all childs of node. Is there a method to get only desired child nodes? For example I want to get only node elements wtih tag "coordinate". Or alternatively, is there a method to exclude text node to be added to the NodeList? My problem is that depending on the xml is formatted, text node could be recognized and added from parser, and this causes problems with my parsing..
thanks to allIf you want to select nodes based on changing criteria, you should use XPath.
If you have relatively fixed criteria, iterate over the nodes and pick out the ones that you want. For example:
public static List<Element> getChildren(Element parent, String tagname) {
List<Element> result = new ArrayList<Element>();
NodeList children = parent.getChildNodes();
for (int ii = 0 ; ii < children.getLength() ; ii++) {
Node child = children.item(ii);
if ((child.getNodeType() == Node.ELEMENT_NODE) && tagname.equals(child.getNodeName()) {
result.add((Element)child);
return result;
} -
How to get only expanded node after open & close in CL_GUI_ALV_TREE?
Hi,
I have a tree structure using CL_GUI_ALV_TREE.
I would like to capture only the expanded nodes AFTER open and close operation.
If the user opens all the nodes and then closes them, I get all the nodes when using GET_EXPANDED_NODES.
I want to get only the expanded nodes that the user currently sees on the screen (so in open and close you will not get it as open).
whatever I tried doesn't work.
Do you have any idea how to do it?
Thanks,
Itaythis methods calls method of attribute MR_COLUMN_TREE without setting the parameter NO_HIDDEN_NODES to 'X'
that's why you get every node that is "open" even if not "visible"
as this attribute MR_COLUMN_TREE is protected, you cannot access it...
you should consider using an object of class CL_GUI_COLUMN_TREE directly in place of CL_GUI_ALV_TREE so that you can call the method with this parameter set...
you will have far more to do by hand but you will get more flexibility... -
How to get only the first result in extract function
do you know how to get only the first element of the function extract.
v_result := p_response.doc.extract('//'||p_name||'/child::text()').getstringval();
if i have 5 responses like '100','100',100','200','200' e get '100100100200200' and i want only '100'.
thanks in advanceTwo ways .....
1. Use Javascript E4X instead ...there are nice functions for getting children of parents.
2. Cycle through all of the form1.nodes and look for objects that have a className of "subform". For loops are useful for this task.
Make sense?
Paul -
In Table Control How to get only a single row .
Hi
In Table Control How to get only a single row .I am able to decrease it its height to 4 but then 2 rows is getting dsplayed .I want only one row to be display and 2nd row should be deactivated or not visible.
regards
Avik
Edited by: Julius Bussche on Jan 30, 2009 1:10 PM
Removed friendly greeting from the subject titleHi Avik
use this code it will help you.
MODULE passdata OUTPUT.
READ TABLE it_revision INTO wa_rev INDEX tab_clc-current_line.
IF sy-subrc = 0.
LOOP AT SCREEN.
IF screen-group1 = '111'. " 111 IS THE GROUP NAME
screen-input = 1. " input mode
screen-active = 1. " input mode.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ELSE.
LOOP AT SCREEN.
IF screen-group1 = '111'. "GROUP NAME
screen-input = 0. " display mode
screen-active = 1. " DISPLAY MODE.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
ENDMODULE. " PASSDATA OUTPUT
Make sure in group tou are passing the field name that you want in input mode on the base of other field
Hope it will help you.
Thanks
Arun Kayal. -
When in a hierarchy, a user right clicks on a node to crate a new node, he has two options
-Child
-Sibling
Is it possible to restrict the user from creating a sibling and allow him to ONLY create child nodes?
Business cases:
1. different level nodes need to have different prefixes.
- Thus, the default prefix property definition uses the level number to assign a prefix
- Also, a validation, to ensure the correct prefix, uses the level number
But if the user can create a child and a sibling then the default prefix will only be right for a single case and not both.
ThanksIf the images are exactly the same size then make sure the layer with the mask
is the active layer and in the other documents go to Select>Load Selection and choose
your document with the layer mask under Source document and under channel choose the layer mask.
After the selection loads press the layer mask icon at the bottom of the layers panel.
MTSTUNER -
How to get only current exception message from tables
Hi
In my sceanario , I want to have the list of Current MRP exception messages list from table
I understand that MRP detailed lists, including all exception messages, are stored in transparent table MDKP and cluster table MDTC.
I can tell ABAPer to write a report for me , to read the data from these tables , but I guess these tables contain old exception message also , which are not currently appearing in MRP list
How to get only current exception message
Rgds,
sandeepSandeep,
MDTC contains only data from the most recent MRP run. So, all messages you see are those which are currently valid.
The messages might have first appeared during a previous run, but they still need to be addressed.
Before you invest a lot of time and effort into writing and debugging a custom report, you should probably try to use the standard SAP functionality found in MD06. On the Processing indicator tab, you can select "Only with new exceptions". Here you can tag a material/plant as 'processed', and thereafter, the exceptions that existed there before you tagged the part will not be re-displayed.
Best Regards,
DB49 -
How to get Value of tree node without Reload Page
hi,
i worked with apex 4.2 and i created Tree and tabular form to retrieve the date according the value of tree select node the code of tree something like this
select case when connect_by_isleaf = 1 then 0
when level = 1 then 1
else -1
end as status,
level,
"ENAME" as title,
null as icon,
"EMPNO" as value,
null as tooltip,
'f?p=36648:34:5234984107903::::P40_SELECTED_NODE:'||empno as link
from "DEPT"."EMP"
start with "MGR" is null
connect by prior "EMPNO" = "MGR"
order siblings by "ENAME
and i put Selected Node Page Item: P40_SELECTED_NODE . the tree worked good and retrieve the data into tabular form according to tree node value
my Question :
1- i want to retrieve the data without submit the page where each time i select value from tree make page reload to update the tabular form with new value ,there is any way to pass the value of tree node to P40_SELECTED_NODE item and refresh tabular form without page reload .
2- i want when selected from tree run page process according to value of tree node i tray to create Dynamic action with *(jquery selector : div.tree li>a)* but the Value of node incorrect.
Regards
Ahmed;look at this link
Re: How to get Value of tree node without Reload Page ..! -
How to get my images always order by arquive name, and not by time of captur, in all the folders in the library?
Sorry for the poor english, but im portugues.
In the library we can change the order of classification of image by, time of capture, name of file etc... I'm wondering if its possible define to be always by the name of file.
It ´s possible?
And i have other question, in print label we have an option to auto rotate to feet in page to have the image using the maximum area in the page (auto rotate, zoom etc), its possible to change the orientation of the rotation to be always in the other direction?The Muvos are USB Mass Storage devices and do not have the ability to display track information based upon ID3 tags.
The Zens all read and display track info based upon ID3 tag information that is either gathered from an online source or entered by the end-user.
If you want the track information displayed instead of the ID3 tag information, you could edit the ID3 tags and rename the title to whatever you have as the file name. Not sure why your file names would differ so much from the ID3 tag info though, almost all of my content has the same name for the filename as it does on the ID3 tag title. -
How to get a text between two XML tags?
Hello everybody!
I've got a problem! How can I extract a text that is between tags, like <myTag> My text </myTag> I have no problem to get the attributes inside the tags, however, i don't know how to get some text that is between tags. Here is my xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<tangram_request service_id="3">
<send keep_session="nada">
<source></source>
<destination>3196931566</destination>
<channel_id>2</channel_id>
<text>Teste ServerSocket!!!</text>
</send>
</tangram_request>
Now, there's a fragment of my code, which gets some tags' attributes:
DOMParser parser = new DOMParser();
InputSource resp = new InputSource(new StringReader(XML));
parser.parse(resp);
Document doc = parser.getDocument();
Node node =(doc.getElementsByTagName "tangram_request")).item(0);
if (node instanceof Element)
Element el = (Element) node;
service_id = el.getAttribute("service_id");
System.out.println("\n\nService_id="+service_id);
}else{System.out.println("Erro");}
node = (doc.getElementsByTagName("send")).item(0);
if (node instanceof Element)
Element el = (Element) node;
keep_session = el.getAttribute("keep_session");
System.out.println("keep_session="+keep_session);
}else{System.out.println("Erro");}
Now, I want to get the texte between <destination> ... </destination>
How could I do that?
Thanks a lot
CalegariThanks... It worked fine!!!
Now how can I get lots of <desctination>... I did something that haven't worked...
node = (doc.getElementsByTagName("destination")).item(0);
while(node.hasChildNodes())
destination = node.removeChild(node.getFirstChild()).getNodeValue();
System.out.println("destination="+destination);
And now, my XML is like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<tangram_request service_id="3">
<send keep_session="nada">
<source></source>
<destination>3196931566</destination>
<destination>3196931567</destination>
<channel_id>2</channel_id>
<text>Teste ServerSocket!!!</text>
</send>
</tangram_request>
Thanks so much!
Calegari -
Need to Get only the Child ID? how to achieve it?
Hi
Lets consider the following situation,
Task_ID TASK_NO Parent_ID TOP_TASK_ID
10 00112
11 00113 10 10
12 00114 10 10
13 00115 10 10
14 00116 13 10
I need to get only child task_id ( 11,12,14)
Task ID = 10 is the Top Level Task
Task ID (11,12,13) are child of Task ID 10
Task ID (14) is a child of Task ID 13
I need to get only child task_id (11,12,14) not 13 because it is a parent of some other task_id..
how to achieve this...
Can some one guide me!maybe this will help.
SQL> Select Lpad(' ', Level*3) || ename name, lpad(' ', Level*3) || job position
2 from emp
3 Start With mgr is null
4 Connect By Prior empno = mgr;
NAME POSITION
KING PRESIDENT
JONES MANAGER
FORD ANALYST
SMITH CLERK
SCOTT ANALYST
ADAMS CLERK
BLAKE MANAGER
ALLEN SALESMAN
WARD SALESMAN
MARTIN SALESMAN
TURNER SALESMAN
JAMES CLERK
CINDY SALESMAN
TINA SALESMAN
CLARK MANAGER
MILLER CLERK
16 rows selected
SQL> select e.name,
2 e.position
3 from (Select Lpad(' ', Level*3) || ename name, lpad(' ', Level*3) || job position, level lv
4 from emp
5 Start With mgr is null
6 Connect By Prior empno = mgr) e
7 where e.lv > 1;
NAME POSITION
JONES MANAGER
FORD ANALYST
SMITH CLERK
SCOTT ANALYST
ADAMS CLERK
BLAKE MANAGER
ALLEN SALESMAN
WARD SALESMAN
MARTIN SALESMAN
TURNER SALESMAN
JAMES CLERK
CINDY SALESMAN
TINA SALESMAN
CLARK MANAGER
MILLER CLERK
15 rows selected
SQL> -
How to get only the first level of nodes for a subform?
How can we get only the first level of nodes of a subform?
For ex:
Form1
SubForm1
Text1
Text2
RadioButton1
SubForm2
Text1
Text2
RadioButton1
SubForm3
Text1
Text2
SubForm31
RadioButton1
In this heirarchy if we give Form1.nodes will refer to all nodes under the Form1 (SubForm1,Test1,Text2,RadioButton1,SubForm2,...SubForm31, RadioButton1 etc..)
But is there any way that we can access only the first level of nodes of Form1 ie can we get only (SubForm1,SubForm2,SubForm3) for Form1 in any Way..?
Thanks.Two ways .....
1. Use Javascript E4X instead ...there are nice functions for getting children of parents.
2. Cycle through all of the form1.nodes and look for objects that have a className of "subform". For loops are useful for this task.
Make sense?
Paul
Maybe you are looking for
-
In R12 can we have approval based on rules like Cost Cente or Account?
Hi All, -In R12 GL can we have approval based on rules like Cost Centers or Account. I know a rule based on Amount can be setup -In R12 GL can we use the PO hierarchy and its Rules Thanks.
-
Set default reader extened to save a pdf form using reader?
is there a way to set it so all forms created are Reader exteneded so they can be saved. why is that shut off anyway? I want them to be able to save it and send it back to me? So now I have to go in an manually open each one andclick several options
-
Purchase price variance based on Receiving QUALITY
Problem Statement: The client have a requirement that when he places an Order to the vendor for a certain commodity, he agrees to a certain level of Quality Parameters and an agreed Rate based on these parameters. Example: $100/Kgs on a condition tha
-
Issue with right aligning of Character Styles in my TOC
Hello all! I'm working on my very first book project and I have been reading soooo many threads on here for the past hour, but i either just don't get it, or i didn't find what i needed still, so i already apologize in case this very question has bee
-
I use QuickTimePlayer X to record videos but suddendly it stop working. I deleted to redownload it but now i can't find it anywhere on the web...