I am trying to come up with a Java code where I can read a xml file
and extract particular element/attribute. This is the structure of xml
I have
<RootElement>
<colAttempt>
<Attempt1 a="1" b="abc>
<ResultElemen t Result = "123" Msg="success">
<nodeList>
<NodeIwant nodeName="conf" noFail="1">
<Data ProgId="294"/>
</NodeIwant>
<NodeIwant nodeName="nconf " noFail="0">
<Data ProgId="3"/>
</NodeIwant>
</nodeList>
</ResultElement>
</Attempt1>
<Attempt2 c="2" d="abc>
<ResultElemen t Result = "123" Msg="success">
<nodeList>
<NodeIwant nodeName="xyz" noFail="0">
<Data ProgId="4"/>
</NodeIwant>
</nodeList>
</ResultElement>
</Attempt2>
</colAttempt>
</RootElement>
I need to extract <NodeIwant nodeName="" noFail =""for each
iteration of Attempt.In the above example, I have two Attempts ( 1 and
2 ). So my output should show, for attempt 1 following result
<NodeIwant nodeName="conf" noFail="1">
<NodeIwant nodeName="nconf " noFail="0">
For attempt 2 following
<NodeIwant nodeName="xyz" noFail="0">
So final result should be like this,
Attempt 1:
<NodeIwant nodeName="conf" noFail="1">
<NodeIwant nodeName="nconf " noFail="0">
Attempt 2:
<NodeIwant nodeName="xyz" noFail="0">
NEED HELP! 1 2540
brahatha wrote:
So final result should be like this,
Attempt 1:
<NodeIwant nodeName="conf" noFail="1">
<NodeIwant nodeName="nconf " noFail="0">
Attempt 2:
<NodeIwant nodeName="xyz" noFail="0">
XPath 1.0 selects nodes in a document, it does not change them. Thus if
you select a NodeIwant element node in the XML sample you posted then it
continues to have its child nodes like those Data elements. If you only
need the NodeIwant elements without their child nodes then you need an
XSLT transformation.
As for the XPath
/RootElement/colAttempt/*[starts-with(name(),
'Attempt')]/ResultElement/nodeList/NodeIwant
should do to select all those NodeIwant elements, if you want to do it
in two steps then first select
/RootElement/colAttempt/Attempt1
and
/RootElement/colAttempt/Attempt2
and then relative to that
ResultElement/nodeList/NodeIwant
--
Martin Honnen http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MegaZone |
last post by:
I'm having some issues with PHP DOMXML - in particular the
get_elements_by_tagname method. Now, the PGP docs on this are, well,
sparse, so maybe I'm just doing something stupid. I thought this
method would behave like the 'findnodes' XML method in Perl. Namely
that you can pass it an xpath statement and it will find nodes that
match:
$array = $node->get_elements_by_tagname($xpath);
This is long so here's a pagebreak:
And, indeed,...
|
by: Iain |
last post by:
I want to create an XML configuration file which might look like
<REGION Name="Europe" WingDing="Blue">
<COUNTRY Name="UK" WingDing="white">
<TOWN Name="London" WingDing="Orange" />
</COUNTRY>
</REGION>
<REGION Name="NorthAmerica" WingDing="Yellow">
<COUNTRY Name="Canada">
<TOWN Name="Quebec" WingDing="Brown" />
|
by: Daniel Frey |
last post by:
Hello,
I'd like to extract the name of an indirectly addressed element by
subsequently using the childs position:
001 <a>
002 <b1/>
003 <b2/>
004 <b3/>
005 </a>
|
by: Amadej |
last post by:
Hello everyone,
I need some advice on which class to use when working with an XML file
in a specific way. Basically I am writing a program, that needs to
save it's state into a file, so it can be read when it starts up
(based on where it ended). It's just 3 elements, with a short text and
a number associated to it. Something like this:
<element><name>something</name><number>3</number></element>
|
by: Steven |
last post by:
Following is the string ...
<ADDRESSINFO name = "Cedar Ave" no = "21123" attrib ="visible">
<HOUSE name ="main" type ="1" value ="2200"/>
<HOUSE name ="slide" type ="12" value ="123"/>
<HOUSE name ="major" type ="1" value ="1234"/>
<HOUSE name ="branch" type ="1" value ="31980"/>
</ADDRESSINFO>
<ADDRESSINFO name = "5th Street" no = "65653" attrib ="visible">
| |
by: Richard |
last post by:
Hi,
I am trying to use an XmlDocument object to manipulate the default database
instance node of the enterprise template library dataConfiguration section
from a custom installer step:
<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
|
by: awebguynow |
last post by:
with an xpath expr: step1/step2
I'm trying to get the position() of step2, using the qualifying
predicate.
I've seen some suggestions, of ways to do this, using count() instead,
but I'm not sure count would work.
Here's an excerpt from a 2003 post reply by Novatchev
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also, the XPath position() function is defined on the current
*node-list*,
|
by: RichardHatcher.com |
last post by:
I am writing C code using xpath to extract some data from a XML
document. The file uses namespaces, but the name spaces are all listed
in the root node of the file as attributes. I want to extract all the
attributes, so that I can register the namespaces. The document looks
like:
<?xml version="1.0" encoding="UTF-8" ?>
<ConfigDataFile xmlns:SRI="SRI" xmlns:SIW="SIW" xmlns:QBQ="QBQ"
xmlns:VLD="VLD"...
|
by: Tim Hallwyl |
last post by:
Hi, there!
As I understand the XPaht recommendation, the context node is a node;
not a node-list, not XPath object -- but a single node.
Now, the WS-BPEL 2.0 specification allows an XML simple type value to be
the context of an XPath expression, by converting it to an XPath object
-- either boolean, string or float.
I do not see how this is possible, but I would like your thoughts on it.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |