Getting the name of the node in Xpath
Hey Guys,
I have a huge XML file that am parsing using XPath. I was able to get most of what i wanted. But i have been having problems when there is a tag with an attribute.
How can i get the value of the attribute given the nodes name?.
Would appreciate your help guys.
kay
The XPath expression for attribute is tag-name/@attribute-name
Similar Messages
-
How to get the Node Value from XmlValue result?
Hi ,
I am not able to get the Node Value from the result. In my XQuery im selecting till a Node, if i change my query as
collection('PhoneBook')/phone_book/contact_person/address/string()", qc);
im getting the node value, but here the problem is its not a Node so i cannot get the Node name.
So how can i get the Node Name and Node value together?
any help please ????
XML :
<?xml version="1.0" encoding="UTF-8"?>
<phone_book>
<contact_person>
<name>
<first_name>Michael</first_name>
<second_name>Harrison</second_name>
</name>
<address city="yyyyy" pincode="600017" state="xxxxx">
176 Ganesan street, Janakinagar, alwarthirunagar
</address>
</contact_person>
<phone_number type="mobile">9881952233</phone_number>
<phone_number type="home">044-24861311</phone_number>
<phone_number type="office">080-12651174</phone_number>
</phone_book>
Code:
XmlQueryContext qc = manager.createQueryContext();
XmlResults rs = manager.query
("collection('PhoneBook')/phone_book/contact_person/address", qc);
while(rs.hasNext()){
XmlValue val = rs.next();
System.out.println(val.getNodeName() + " = [ " + val.getNodeValue() + " ] ");
Output
address = [ ]You are right, this seemed un-intuitive to me too, but I finally understood how it's done.
The "value" of a node is actually the total amount of text that is not contained in any of the node's child nodes (if any). So a node with child nodes can still have text value.
To get the 'value' of an element node, you must therefore concatenate the values of all children of type "XmlValue::TEXT_NODE", of that node. Try it.
In your example, the <address> node has no child elements, my guess is that BDB XML stores the address string "176 Ganesan street, Janakinagar, alwarthirunagar" inside a child node of <address> node (of type XmlValue::TEXT_NODE) because you wrote the string on a separate line. -
Issue using extractval to get the node value when there is namespace
I created the db with a XMLType column:
CREATE TABLE mytable1 (key_column VARCHAR2(10) PRIMARY KEY, xml_column1 XMLType);
Then inserted one row:
INSERT INTO mytable1 (key_column,xml_column1) VALUES ('test', XMLType('<MY_TEST xmlns="http://xmlns.oracle.com/ku" version="1.0">
<SCHEMA>SYSTEM</SCHEMA>
<NAME>TABLE41</NAME>
<TEST_GROUP>TEST_GRP_RMP</TEST_GROUP>
<TEST_NAME>DEPARTTEST</TEST_NAME>
<FUNCTION_SCHEMA>SYSTEM</FUNCTION_SCHEMA>
<TEST_FUNCTION>EXCLUDE_TABLE</TEST_FUNCTION>
<STATEMENT_TYPE_LIST>
<STATEMENT_TYPE_LIST_ENTRY>
<NAME>SELECT</NAME>
</STATEMENT_TYPE_LIST_ENTRY>
</STATEMENT_TYPE_LIST>
<UPDATE_CHECK>Y</UPDATE_CHECK>
<ENABLE>Y</ENABLE>
<STATIC_POLICY>N</STATIC_POLICY>
<TEST_TYPE>DBMS_RLS.DYNAMIC</TEST_TYPE>
<LONG_PREDICATE>N</LONG_PREDICATE>
</MY_TEST>'));
Then I ran:
select extractValue(xml_column1,'MY_TEST/TEST_NAME') policy from mytable1;
There is nothing returned.
If i do not have "xmlns="http://xmlns.oracle.com/ku" " in MY_TEST node, then the correct value returned.
Please advise how could I get the node value when there is namespace? Thanks.This is a known issue. In the third parameter of extractvalue, set the namesapce. Then it works.
-
How to get the node id of the content shown from campaign
Hi
Can any one please tell how to get the node id of the content shown by the campaign
in jsp
ThanksOne option is to define a custom ad renderer, which is registered with the proper mime-type.
The campaign would run your renderer if the campaign retrieved a node with a binary of the proper registered mime-type.
This allows you to insert yourself into the call chain for the node rendering. You can access the nodeID at that point (and do the typical rendering-- providing a URL for the ShowPropertyServlet)
-Steve -
How to get the node value of payload
Hi
The null is returned when I use the following code to get the User_ID element in the payload, but there are values in the User_ID element of the payload
Task task_test = wfSvcClient.getTaskQueryService().getTaskDetailsById(wfCtx, taskId);
System.out.println("the payload value is " + task_test.getPayloadAsElement().getElementsByTagName("User_ID").item(0).getNodeValue());
How to get the node value of payload ? any suggestion?
Thanks
JaysonHi Jayson,
Try:
System.out.println("the payload value is " + task_test.getPayloadAsElement().getElementsByTagName("User_ID").item(0).getFirstChild().getNodeValue());
So add the getFirstChild() call in between.
If this works, maybe consider using JAXB to marshall the payload details to POJO's. This will make reading the payload details much easier.
Regards, Ronald -
How to get the node name?
Hi Guys,
I have a path that look like this root/1stLevel/dynamicLevel
how can i get the dynamic level node name when it come with different node name so that i can catch it into one of the variable?
it may change according to the requester
root/1stLevel/dynamicLevel1
root/1stLevel/dynamicLevel2
root/1stLevel/dynamicLevel3
root/1stLevel/dynamicLevel4What software? In OSB try Assign with this expression:
fn:name($body/root/firstLevel/*[1])By the way, you can't use element named "1stLevel" because it starts with number. -
Just comparing one string how to get the node?
hi group,
I get the string value like this:
String listselvalue = getJList1().getSelectedValue().toString();
Just i am comparing this with particular node.(which is in tree) like this:
TreePath path = getmy_tree().getPathForRow(1);
DefaultMutableTreeNode selnode = (DefaultMutableTreeNode)path.getLastPathComponent();
Enumeration enum = selnode.children();
while(enum.hasMoreElements())
if(enum.nextElement().toString().equalsIgnoreCase(listselvalue))
//here what trick I have to use to get that node.(if it matches)
thank u...
Shalinipriya.You need your node for both your test and your manipulation if the test is succesfull, so just keep a ref to your node before the test, and use that ref for both test and manipulation. Within your code, it should look like this:
Enumeration elts = selnode.children();
while ( elts.hasMoreElements() ) {
// keep a ref to the current node,
// so you can bith test its name
// and manipulate it if it match you critiria
Object currentNode = elts.nextElement();
if ( currentNode.toString().equalsIgnoreCase( listValue ) ) {
// here you have your currentNode object
// that is a DefaultMutableTreeNode
doNodeJob( currentNode );
} -
I have a schema, which has both complex type and simple type elements. I want to parse the schema and get the root element, complex type and simple type element names.
Though i have seen some similar queries in the forum but none of them provide a complete solution.
I have tried using XMLSchema and getXMLSchemaNodeTable() but this gives only the root nodes.
My schema looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.abc.com/schema/teamDesc"
attributeFormDefault="unqualified">
<element name="team">
<complexType>
<sequence>
<element name="teamLongDesc" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="TeamId" type="integer" default="0" />
<element name="TeamCode" type="string" />
<element name="TeamDesc" type="string" />
</sequence>
<attribute name="isMaster" use="required" />
<attribute name="primaryKey" use="required" />
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>Thanks for the reply..when i use schema.getXMLSchemaNodeTable(), the Hashtable contains only the following items, this is as per the schema i have given above
(java.util.Hashtable<K,V>) {http://www.ifs.com/schema/teamDesc=oracle.xml.parser.schema.XMLSchemaNode@124e935, http://www.w3.org/2001/XMLSchema=oracle.xml.parser.schema.XMLSchemaNode@4ac866} -
How to get the node's coordinates when Node is in a managed container
I worked thru the documentation of "BoundsInParent and BoundsInLocal" but these values do not seem to be resonable when the Node is within a managed container
e.g. when the node is placed in a HBox or BorderPane.
How can I estimate the y-coordinate of this node (relative to the scene) ?Have you tried Node's "localToScene" method?
-
Function Module to get the node name in particular level name in Hierarchy
Hi All,
We have 0Material hierarchy which consists of 14 levels and materials are in the 14th level.
We have a requirement to update the 4th level node name to all materials.
So we have created the attribute to this 0Material and thought of updating in the transformation.
Could you please suggest us to which function module i can in this scenario.
Thanks in advance,..
PrasannaCan you explain in more detail what exactly you want to do?
do you want to limit hierarchy to level4?
Regards
Sudeep -
Get the node key while using button on toolbar
HI All
I'm using alv tree (class - CL_GUI_ALV_TREE ) and I want to add a button
to the toolbar (class - CL_GUI_TOOLBAR ) that User can delete
a row from the tree .
assume the user put the cursor on row
how can i know on which node_key is it ?
I am using the event function selected for the button ...
Regards
AlexAlex,
check this sample program BCALV_TREE_04
call method g_alv_tree->get_selected_nodes
changing
ct_selected_nodes = lt_selected_nodes.
Thanks
Bala Duvvuri -
How to get the name and value of an attribute on a node/element that is not a child
Hello,
Can someone shed some wisdom on how I can compare 2 xml nodes for differences.
My main challenge is I need to use the attributes/values of 'ProductDescription' and 'Features' as 'key' to identify the same node in
another doc with the same layout, but different content.
I am having trouble getting the name of the attribute on the node, 'ProductDescription' and 'Features'. I can only seem to get the node names, but not the attributes on the node. I need the name, because it can be different from doc to doc, so
I can't hardcode this.
Can someone please help with how to retrieve an attribute name/value on a node that is not a child. Here's an example of what
my xml looks like:
DECLARE
@myDoc1 xml
,@mydoc2 xml
DECLARE
@ProdID int
SET @myDoc1 ='<ProductDescription ProductID="1" ProductName="Road Bike">
<Features featureID = "1" featureName = "body">
<Warranty>1 year parts and labor</Warranty>
<Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
<features featureID = "2" featureName = "seat">
<Warranty>1 year parts and labor</Warranty>
<Maintenance>2 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>
SET @myDoc2 ='<ProductDescription ProductID="1" ProductName="Road Bike">
<Features featureID = "1" featureName = "body">
<Warranty>2 year parts and labor</Warranty>
<Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
<features featureID = "2" featureName = "wheel">
<Warranty>1 year parts and labor</Warranty>
<Maintenance>2 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>
I need to compare the attributes of 'ProductDescription' and 'Features' from @mydoc1 against @mydoc2 to see if they are the same based on those 2 nodes first. If they are, then i want to show the difference in the child elements.
This will eventually be an outer join to give me the differences betw the 2 docs based on those key values (node attributes).
I used node('//*') for the path, and value('local-name(../.)', 'varchar(50)') as element
,value('.[not(@xsi:nil = "true")]','VARCHAR(255)') AS new_value
...etc...
but that only gives me the node names, and the child elements. It does not give me back the attribute names and values from the node itself.
Thanks in advance for your help.
ceeAre you looking for something like this:
DECLARE @myDoc1 xml
SET @myDoc1 ='<ProductDescription ProductID="1" ProductName="Road Bike">
<Features featureID = "1" featureName = "body">
<Warranty>1 year parts and labor</Warranty>
<Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
<Features featureID = "2" featureName = "seat">
<Warranty>1 year parts and labor</Warranty>
<Maintenance>2 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>'
SELECT T.c.value('local-name(.)', 'nvarchar(50)') AS name,
T.c.value('.', 'nvarchar(50)') AS value
FROM @myDoc1.nodes('ProductDescription/@*') AS T(c)
Erland Sommarskog, SQL Server MVP, [email protected] -
How to get the folder name of selected subitem in tree structure?
Hi All,
I created a tree structure like below.
->Folder1-- 1
2
3
->Folder2-----1
2
3
i.e i have two folders & each folder having the values like above.Now i want to perform some action by clicking on the any of the values.Suppose if i click value 2,i want to do some action.the actions need to perform is varies from floder to to folder.
So How can i get the folder name of clicked Value?
Regards,
RaviHi Kumar ,
the below code should help you.
Register the below action for the leaf node for which u need the subfolder's name above it.
Worked fine in my system ...hope it does in ur scenario too
method ONACTIONGET_PATH .
data : lr_element TYPE REF TO if_wd_context_element,
lr_node TYPE REF TO if_wd_context_node,
ls_path type string,
ls_path_node TYPE string,
lt_string type TABLE OF string,
l_lines type i,
l_lines_1 TYPE i.
lr_element = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
**-> getting the path of the node/leaf
*which u had clicked and from that getting the node above it
ls_path = lr_element->get_path( ).
SPLIT ls_path at '.' into table lt_string.
-> remove the first 2 entries as they will contain the view name
DELETE lt_string FROM 1 to 2.
l_lines = LINES( lt_String ).
l_lines_1 = l_lines - 1.
-> remove the last 2 entries as they will contain the element in the path
DELETE lt_string from l_lines_1 to l_lines.
LOOP AT lt_string into ls_path.
CONCATENATE LINES OF LT_STRING into ls_path_node SEPARATED BY '.'.
ENDLOOP.
**-> getting access to the node above the leaf element
LR_NODE = WD_CONTEXT->PATH_GET_NODE( path = ls_path_node ).
lr_element = lr_node->get_element( ).
**-> Getting the name of the folder...
*here path is the attribute in my context which stores the name of the folder
lr_element->get_attribute( EXPORTING name = 'PATH' IMPORTING value = ls_path ).
endmethod. -
How to map the node id to the node name in database view just like "V$GES_RESOURCE"
i have a rac with 3 nodes,and the node id is from 1 to 3,i can check it with command olsnodes.
$ olsnodes -p -n -i
tdsdb1 1 tdsdb1-priv tdsdb1-vip
tdsdb2 2 tdsdb2-priv tdsdb2-vip
tdsdb3 3 tdsdb3-priv tdsdb3-vip
and i also can check it in gv$instance
SQL> select inst_id,instance_number,instance_name from gv$instance;
INST_ID INSTANCE_NUMBER INSTANCE_NAME
1 1 jftds1
3 3 jftds3
2 2 jftds2
but when i select the master node of some resource ,it shows some value of node id =0
SQL> select resource_name,master_node from v$ges_resource;
RESOURCE_NAME MASTER_NODE
[0xdcc9fa12][0x246658a5],[QQ] 2
[0x932][0x70c230e],[IV] 0
[0xd9fb][0x13181703],[IV] 0
[0xddae][0x0],[TM] 0
[0xb970fb05][0x729b596a],[LB] 2
[0xb580][0x70c2e1c],[IV] 0
[0x31ad56fb][0x7e4c3daa],[QQ] 2
[0x3][0x797609],[HW] 0
[0x2bf04627][0xf28b1575],[QI] 0
[0x19c89f33][0xd06ef447],[QQ] 0
[0x529ae82][0x86e25d46],[QQ] 0
it seems that the master node id is from 0 to 2
i want to get the node name from the node id from v$ges_resource,so i check the table cluster_nodes ,cluster_instances,but there are nothing.
SQL> select * from CLUSTER_NODES;
no rows selected
SQL> select * from CLUSTER_INSTANCES ;
no rows selected
how can i get the node name from the node id in the tables just like " v$ges_resource"? thank you .my cluster ware version is 10.2.0.5
database version is 10.2.0.5
and the source of rac is all online
$ crsctl query crs activeversion
CRS active version on the cluster is [10.2.0.5.0]
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.5.0 - Productio
NLSRTL Version 10.2.0.5.0 - Production
$ crs_stat -t
Name Type Target State Host
ora.jftds.db application ONLINE ONLINE tdsdb2
ora....tds1.cs application ONLINE ONLINE tdsdb1
ora....s1.inst application ONLINE ONLINE tdsdb1
ora....ds1.srv application ONLINE ONLINE tdsdb1
ora....tds2.cs application ONLINE ONLINE tdsdb2
ora....s2.inst application ONLINE ONLINE tdsdb2
ora....ds2.srv application ONLINE ONLINE tdsdb1
ora....tds3.cs application ONLINE ONLINE tdsdb3
ora....s3.inst application ONLINE ONLINE tdsdb3
ora....ds3.srv application ONLINE ONLINE tdsdb3
ora....SM1.asm application ONLINE ONLINE tdsdb1
ora....B1.lsnr application ONLINE ONLINE tdsdb1
ora.tdsdb1.gsd application ONLINE ONLINE tdsdb1
ora.tdsdb1.ons application ONLINE ONLINE tdsdb1
ora.tdsdb1.vip application ONLINE ONLINE tdsdb1
ora....SM2.asm application ONLINE ONLINE tdsdb2
ora....B2.lsnr application ONLINE ONLINE tdsdb2
ora.tdsdb2.gsd application ONLINE ONLINE tdsdb2
ora.tdsdb2.ons application ONLINE ONLINE tdsdb2
ora.tdsdb2.vip application ONLINE ONLINE tdsdb2
ora....SM3.asm application ONLINE ONLINE tdsdb3
ora....B3.lsnr application ONLINE ONLINE tdsdb3
ora.tdsdb3.gsd application ONLINE ONLINE tdsdb3
ora.tdsdb3.ons application ONLINE ONLINE tdsdb3
ora.tdsdb3.vip application ONLINE ONLINE tdsdb3 -
HOW TO GET THE VALUE OF A NODE IN XMLDOC?
i have an xml doc like this:
<FUSIONHUB>
<INFO>
<COMPANY_ID>A001</COMPANY_ID>
</INFO>
</FUSIONHUB>
HOW TO RETRIEVE THE VALUE A001?
I HAVE USED NODE.getNodevalue() method but it returned null instead of A001.
can anybody please answer ?
waitng for replies immediately.
nullHi,
You need to get the child node of the company_id node and then get the node value.
The value A001 is stored in a textnode under the node company_id.
Thanks,
Oracle XML Team
Maybe you are looking for
-
InDesign (CS 5.5) won't print fonts from a file that prints correctly in CS 3
Hello, I installed CS 5.5 last night and installed all of the updates (on Windows XP with SP3). I have an Okidata B4300 laser printer with Postscript 3 emulation installed. Several typefaces (both True Type and Open Type, 4 fonts tested so far) are n
-
I get this msg when I try to relink my media files. Im lost because I have not changed any formats or where the files are located. 83 name matches were found, but 83 files are not compatible. Relinked files must have the same media type and similar
-
I need to install the find my iPhone app on my ipad, it will not install. Any reasons. Do I need to change something in my settings? I am up to date with my ios7. Please help!
-
An extra prompt appears for Credentials Opening Office Document in Workspac
Hi, Anybody have any knowledge about this issue? and how to solve these issue? *6959959* An extra prompt appears for Credentials Opening Office Document using Internet Explorer with Smartcut or from EPM Workspace. If a security agent with a cookie-ba
-
I am current having a problem wwith flash player 9 under windows 98. It seem that when I visit a site that uses Flash player that Flash keeps using more and more of the system memory to the point that the system resources will be exhausted, causing t