f



How to get value of XML "Element " type node

Hi,

I want to fetch some values from a XML file, using a java program.
I want to retrieve value of path tag for e.g<path>some path</path>
tag.(Marked with **** in the below XML file Example)

=============
My XML File
============

<maindata id="U00abfd8a-0ce7-ced5-00f6-00fff5bfdea9" host="e05k02"
addr="10.64.33.86" domain="BrioPortal 7.0 Development"
version="7.0.1.17" date="2003-08-04 14:20:23-07">
<Category name="MigSMACT" version="7.0.1.17"
id="U01929031-0e01-ced5-00f6-00fff5bfdea9">
  <gendate>2003-08-04 14:20:25-07</gendate>
  <cattribs>
    <autodelete>false</autodelete>
    <browsable>true</browsable>
    <datecreated>2003-07-28&sp;14:35:33-07</datecreated>
    <description>New&sp;Category</description>
    <group name="ADMINISTRATOR"
idref="U0159c5ff-13e4-ced5-00f6-00fff5bfdea9"/>
    <lastmodified>2003-07-28&sp;14:35:33-07</lastmodified>
    <name>MigSMACT</name>
    <objectid>HXLWIRBZFXECHBDYAGHLIRRPZe0Ck0N-BCRRP_Z0FK0N</objectid>
    <objecttype mimetype="Category"
idref="U00d5f038-13e8-ced5-00f6-00fff5bfdea9"/>
    <owner name="dw1portl"
idref="U0057d3f5-143b-ced5-00f6-00fff5bfdea9"/>
    <parentcategory name="Migration Staging"
idref="U001c7c0d-1456-ced5-00f6-00fff5bfdea9"/>
    <parentobjectid>FBRGZLXIDHCITIDYG0R0LLP_eZFkZC-FCLRB_E0FM0C</parentobjectid>
****** <path>/ABC&sp;Shipping/Goods&sp;Sale/Final</path> *******
    <permissions>
      <Permissions>
        <groupexecutepermission>true</groupexecutepermission>
        <groupreadpermission>true</groupreadpermission>
        <groupwritepermission>true</groupwritepermission>
        <ownerexecutepermission>true</ownerexecutepermission>
        <ownerreadpermission>true</ownerreadpermission>
        <ownerwritepermission>true</ownerwritepermission>
        <worldexecutepermission>true</worldexecutepermission>
        <worldreadpermission>true</worldreadpermission>
        <worldwritepermission>true</worldwritepermission>
      </Permissions>
    </permissions>
  </cattribs>
</Category>

==============
My Java Code
=============

DOMParser tParser = new DOMParser();
tParser.parse("WRTest_11-28-5:38_sdw-sb.xml");
Document doc = tParser.getDocument();

doc.getDocumentElement ();
System.out.println ("Root element :" +
doc.getDocumentElement().getNodeName());

NodeList objCatNodes = doc.getElementsByTagName("path");

int totalCatNodes = objCatNodes.getLength();
System.out.println("Total no of Path tags: " + totalCatNodes);

Node objNode=objCatNodes.item(0);
System.out.println("Path Name : " + objNode.getNodeName());

-------------------------------------
In the last System.out.println, it is returning NULL. 

Please tell me what I need to do, to get the value. Plz help me its
Urgent. thanks in advance.

Amy..........
0
amol107 (4)
11/29/2003 1:30:36 PM
comp.text.xml 8781 articles. 0 followers. Post Follow

1 Replies
426 Views

Similar Articles

[PageSpeed] 5

The following will give you what you are looking for:


import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.*;

public class amol {
		
    public static void main(String[] args) {
    
    try {
        DOMParser tParser = new DOMParser();
		  
        tParser.parse(args[0]);
	Document doc = tParser.getDocument();
	doc.getDocumentElement();
	System.out.println ("Root element :" +
	   doc.getDocumentElement().getNodeName());

	NodeList objCatNodes = doc.getElementsByTagName("path");

	int totalCatNodes = objCatNodes.getLength();
	System.out.println("Total no of Path tags: " + totalCatNodes);

	Node objNode=objCatNodes.item(0);
		  
	NodeList objNodes = objNode.getChildNodes();
	System.out.println("Path Name : " + objNodes.item(0).getNodeValue());
		  
	} catch (Exception e) {e.printStackTrace();}
    }
	
}

Enjoy!

- Finnbarr


amol107@indiatimes.com (Amol) wrote in message news:<fc443593.0311290530.1b0436bf@posting.google.com>...
> Hi,
> 
> I want to fetch some values from a XML file, using a java program.
> I want to retrieve value of path tag for e.g<path>some path</path>
> tag.(Marked with **** in the below XML file Example)
> 
> =============
> My XML File
> ============
> 
> <maindata id="U00abfd8a-0ce7-ced5-00f6-00fff5bfdea9" host="e05k02"
> addr="10.64.33.86" domain="BrioPortal 7.0 Development"
> version="7.0.1.17" date="2003-08-04 14:20:23-07">
> <Category name="MigSMACT" version="7.0.1.17"
> id="U01929031-0e01-ced5-00f6-00fff5bfdea9">
>   <gendate>2003-08-04 14:20:25-07</gendate>
>   <cattribs>
>     <autodelete>false</autodelete>
>     <browsable>true</browsable>
>     <datecreated>2003-07-28&sp;14:35:33-07</datecreated>
>     <description>New&sp;Category</description>
>     <group name="ADMINISTRATOR"
> idref="U0159c5ff-13e4-ced5-00f6-00fff5bfdea9"/>
>     <lastmodified>2003-07-28&sp;14:35:33-07</lastmodified>
>     <name>MigSMACT</name>
>     <objectid>HXLWIRBZFXECHBDYAGHLIRRPZe0Ck0N-BCRRP_Z0FK0N</objectid>
>     <objecttype mimetype="Category"
> idref="U00d5f038-13e8-ced5-00f6-00fff5bfdea9"/>
>     <owner name="dw1portl"
> idref="U0057d3f5-143b-ced5-00f6-00fff5bfdea9"/>
>     <parentcategory name="Migration Staging"
> idref="U001c7c0d-1456-ced5-00f6-00fff5bfdea9"/>
>     <parentobjectid>FBRGZLXIDHCITIDYG0R0LLP_eZFkZC-FCLRB_E0FM0C</parentobjectid>
> ****** <path>/ABC&sp;Shipping/Goods&sp;Sale/Final</path> *******
>     <permissions>
>       <Permissions>
>         <groupexecutepermission>true</groupexecutepermission>
>         <groupreadpermission>true</groupreadpermission>
>         <groupwritepermission>true</groupwritepermission>
>         <ownerexecutepermission>true</ownerexecutepermission>
>         <ownerreadpermission>true</ownerreadpermission>
>         <ownerwritepermission>true</ownerwritepermission>
>         <worldexecutepermission>true</worldexecutepermission>
>         <worldreadpermission>true</worldreadpermission>
>         <worldwritepermission>true</worldwritepermission>
>       </Permissions>
>     </permissions>
>   </cattribs>
> </Category>
> 
> ==============
> My Java Code
> =============
> 
> DOMParser tParser = new DOMParser();
> tParser.parse("WRTest_11-28-5:38_sdw-sb.xml");
> Document doc = tParser.getDocument();
> 
> doc.getDocumentElement ();
> System.out.println ("Root element :" +
> doc.getDocumentElement().getNodeName());
> 
> NodeList objCatNodes = doc.getElementsByTagName("path");
> 
> int totalCatNodes = objCatNodes.getLength();
> System.out.println("Total no of Path tags: " + totalCatNodes);
> 
> Node objNode=objCatNodes.item(0);
> System.out.println("Path Name : " + objNode.getNodeName());
> 
> -------------------------------------
> In the last System.out.println, it is returning NULL. 
> 
> Please tell me what I need to do, to get the value. Plz help me its
> Urgent. thanks in advance.
> 
> Amy..........
0
fpm (15)
12/2/2003 4:25:49 AM
Reply:

Similar Artilces:

file command: "XML document text" vs "XML document text"
I've just used the file command on four files of RDF-XML with the following output: augtfidf.rdf: XML document text kyoto.rdf: XML document text stuff.rdf: XML document text tfidf.rdf: XML document text What does it mean that one of them has an extra space between "XML" and "document"? -- The kid's a hot prospect. He's got a good head for merchandising, an agent who can take you downtown and one of the best urine samples I've seen in a long time. [Dead Kennedys t-shirt] On 16.10.2012 16:06, Adam Funk wrote: > I've just used the file command on four files of RDF-XML with the > following output: > > augtfidf.rdf: XML document text > kyoto.rdf: XML document text > stuff.rdf: XML document text > tfidf.rdf: XML document text > > What does it mean that one of them has an extra space between "XML" > and "document"? Hard to tell without further information. What does file *.rdf | od -c show you? Janis Janis Papanagnou wrote: > On 16.10.2012 16:06, Adam Funk wrote: >> I've just used the file command on four files of RDF-XML with the >> following output: >> >> augtfidf.rdf: XML document text >> kyoto.rdf: XML document text >> stuff.rdf: XML document text >> tfidf.rdf: XML document text >> >> What does it mean that one ...

What XML technologies to learn first for "XML Processing" and "XML Mapping"?
Hi, Doing job interviews. I know XML basics, but I want to familiarize myself with the best that XML has to offer at the moment. What do I need to learn? In other words, what is the dominant XML technology being used at the moment for processing? What is the 'struts' of the XML world? I've used a bit of JDOM, DOM4J, and JAXB. I know there are other xml-to-java serialization-type technologies out there that are less cumbersome - which do I need to know first? Which are most interesting? Which could become market leaders? Also, what are alternatives, if any, to XML? I know...

In xml schema, what's the difference between attribute "final" and "block" in element "element"
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element name="city" type="string"/> </sequence> </complexType> and <complexType name="Address" block="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element name="city" type="string"/> </sequence> </complexType> in xml schema? Hi, You can think of final as a development time restriction (applies to schema itself) and of block as a runtime restriction (applies to schema usage from the instance documents). If you have final="restriction" (note that I made city optional to have something to restrict) <xs:complexType name="Address" final="restriction"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType> then trying to create a type like below will fail with a...

Should the webserver add "Content-Type: text/xml header" to the requested XML file?
I've been informed that a webserver sending a XML file is supposed to add "Content-Type: text/xml header". I'm not questioning that infromation but i'm unsure what was ment by it. The XML i get on my screen when i type in the url to it looks as follows. <?xml version="1.0" encoding="UTF-8"?> <tag-uno>uno</tag-uno> <tag-duo>duo</tag-duo> I can't see any line containing "text/xml" but perhaps it's not supposed to show in the requested file. Please advise. -- Regards Konrad Viltersten ---------------...

Setting "text" value to "option" element in IE
I'm creating a select entirely through JavaScript and very strangely IE doesn't show the text in the option elements. Here part of the code: this.form_country=document.createElement("select"); var option; for(var i=0; i<arr.length; i++){ option=document.createElement("option"); option.value=arr[i].code; option.text=arr[i]._value; alert(option.value+" - "+option.text); this.form_country.appendChild(option); } It works perfeclty on FireFox, funny thing is that the alert works properly but there is no way to see any text inside :S Any idea? Of cou...

How to get from A to B (actually, from type "A" to type "B")
I was flabbergasted the first time I used an IDE that had the "period completion" feature (or the similar, "left parenthesis"). It made me considering leaving old trusted "vi". The problem with the period is that it only goes one step deep: more steps are needed! Additionally, sometimes the period is not the answer to your travails, when a non-member function is the one that will convert from type "A" to type "B". When I was learning Java, a large number of questions (and time wasted) that I posted were of the form: "How do I convert [some type] to [some other type]?" The text conversions alone occupy an inordinate amount of time to programmers (just try Google to see what I mean). Some C++ examples: I had been using for a long time this (from Boost::Filesystem): string somestring = "abc/de"; path p = path(somestring); Only to realize, accidentally, that the conversion is done automatically. The IDE should help you in those cases: path p = somestring; This one made me kick myself. I used this many, many times: const char* sometext = somestring.string().c_str(); Well, it turns out that this one is just as good: const char* sometext = somestring.c_str(); My question is about R&D done in this particular field. I tried Google but the word "type" is too ambiguous. This problem is very similar to the resolution of Rubik...

redout of "name", "type" and "value" tags into a string
Hello! I hope you can help me: I have a structure. I can redout and print the structure tags using the TAG_NAMES function. But I also want to readout the "Type" and "Value" tags into a string array. How can I do that? Greetings from Bavaria, Michael On May 21, 5:03 am, BavarianMike86 <jo.mich...@gmx.de> wrote: > Hello! > I hope you can help me: > > I have a structure. I can redout and print the structure tags using > the TAG_NAMES function. > But I also want to readout the "Type" and "Value" tags into a string > array. >...

enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)
My question can be found here: http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python Here is an additional sample sample of the XML that I am working with: <Response ID="123546 - 7831" RequestType="Moverview"> <MonthDayCount> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32> <Int32>0</Int32...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

"column typing" or "multiline editing" and "smart typing"
(1) Is it possible to multiline editing like TextMate (http://macromates.com): http://macromates.com/images/inline/columns.gif ??? (2) And :-) http://macromates.com/images/inline/smart_typing.gif ??? How? -- Szymon Drejewicz Hi Szymon, > http://macromates.com/images/inline/columns.gif See the rectangle commands, C-x r C-h. > http://macromates.com/images/inline/smart_typing.gif See dynamic abbreviations, M-/. Herzliche Gr��e, Christoph -- Jenseits von falsch und richtig gibt es einen Ort. Dort treffen wir uns. Mevlana Celalettin Rumi Christoph Conrad <nospam@spamgo...

"dconj, variable subsititution""how to get numerical value"instead of "dconj"function
dear sir ..if i am doing diff and variable value substitution like... for example >> syms x >> e=sin(x) >> p=diff(e,x,1) p =cos(x) >> subs(p,x,0) ans = 1 i am doing simple trigonometric function answer is coming...but if >>s1=4.15; >>s2=1.05; syms x ; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' a12=(-i)* ( (s1+s2)/( sqrt(((s1+s2)^2+x^2)) ) )*sin(sqrt( s1^2+( (s1*x)/(s1+s2) )^2 )) a21=(a12) t1=sqrt( s1^2+( (s1*x)/(s1+s2) )^2 ) t2=sqrt( s2^2+( (s2*x)/(s1+s2) )^2 ) u= (x/(sqrt( ((s1+s2)^2+x^2) ))) b12=(-i)* ( (s1+s2)/( ...

onclick="element.setAttribute("style",value)"
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a fancy style, but the onclick fails to do anything no matter what permutation of parameters I try. <input type=button style=background-color:yellow;color:blue;font-family:Arial;font-style:italic;font-weight:bold name="xyz" value="CHANGE COLOUR" onclick="xyz.setAttribute('style=backgroundColor':cyan);"/> Can you point me in the right direction? joh...

Why is XML "stupid" about element ordering?
I'm not sure if this has been addressed in more recent developments, but I'm reading the MathML specification which states "For example, it is not possible in XML to specify that the first child be interpreted one way, and the second in another." Is there a compelling reason that XML does not support that capability? Has it been fixed? I recall attempting to create my own schemas a couple years ago, and finding this limitation. For my purposes it was significant. -- .. In article <mLCdndx84IYxJfneRVn-sw@speakeasy.net>, Arturius mac Aidan <abysmal@waters.loch> wrote: >I'm not sure if this has been addressed in more recent developments, but I'm >reading the MathML specification which states "For example, it is not >possible in XML to specify that the first child be interpreted one way, and >the second in another." Since XML doesn't specify how elements are interpreted, this doesn't make much sense. Applications can interpret XML any way they want to. >I recall attempting to create my own schemas a couple years ago, and finding >this limitation. Now you are talking about schemas, which constrain XML and perhaps assign types to it, rather than interpret it. It's true that you can't use XML Schemas to specify different constraints on children of an element with the same name, but there are all kinds of constraints that you can't express. -- Richard Richard Tobin wrote: > In a...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

XML() constructor: "unexpected end of XML entity"?
I'm using XMLHttpRequest in FF 4.01 to grab some records from a mysql db. When I have the records, I roll my own xml in a loop and ship them off to the client, where I pass the responseText buffer to an XML() constructor so that I can use dot notation to access the xml. This works fine for 5 or fewer records. For 6 or more, the XML constructor chokes, complaining about 'unexpected end of xml entity'. Examination of the responseText buffer before the XML() constructor call reveals no problems, and the records themselves are not an issue since the same records will be parsed or not parsed according to how many there are in the dataset. It sounds like a buffer-size problem in the constructor causing the string to be clipped, but I can't find any documentation. Thanks in advance for any ideas about how to solve or evade this. Puzzled wrote: > I'm using XMLHttpRequest in FF 4.01 to grab some records from a > mysql db. > > When I have the records, I roll my own xml in a loop and ship > them off to the client, where I pass the responseText buffer to > an XML() constructor so that I can use dot notation to access the > xml. > > This works fine for 5 or fewer records. > > For 6 or more, the XML constructor chokes, complaining about > 'unexpected end of xml entity'. > > Examination of the responseText buffer before the XML() > constructor call reveals no problems, and the records themselves > are n...

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

Newbie. xml "dynamically" including another xml document
Hi, I have an xml document with customer data. A test example starts like this: <?xml version="1.0" encoding="UTF-8"?> <customer-info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cust-05.xsd"> <!-- Contain all properties of the customer in document element --> <customer cust-number="38273-815"> <cust-name title="Mr."> <first>Clive</first> <middle>Robert</middle> <last>Long</last> etc. I have another xml document with a completely different structure: <?xml version="1.0" encoding="UTF-8"?> <occupation-list> <occupation d="" tv="1" r="" s="" i="" p="" descr="ARCHITECTURE, ENGINEERING, AND SURVEYING">arch-eng-surv</occupation> <occupation d="" tv="2" r="" s="" i="" p="" descr="MATHEMATICS AND PHYSICAL SCIENCES">math-phys</occupation> etc. Now I have an xslt that processes the data in the first xml document but want to "refer" to the second xml document so that when the occupations in the first doc are "looked up" in the second, I can "read" the values of the attributes from the second document (d, i, t...

"In" "Out" and "Trash"
I just bought a new computer and I re-installed Eudora Light on my new computer. But when I open Eudora, the "In", "Out" and "Trash" links are not on the left side of the screen the way they were on my old computer. How can I get these links back on the left side of the screen? Thank you. On 25 Mar 2007 09:49:22 -0700, "abx" <abfunex@yahoo.com> wrote: >I just bought a new computer and I re-installed Eudora Light on my new >computer. But when I open Eudora, the "In", "Out" and "Trash" links >are ...

Does it need a ";" at the very after of "if" and "for"
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if statement? marsarden said: > write code like: > > int main(void) > { > int a=10; > if(a<20) > {} > } > > Compiler ok on dev-cpp . don't we have to add a ";" after if > statement? The syntax for 'if' is: if(expression) statement There is no semicolon after the ) but before the statement. The statement is either a normal statement (which can be empty), ending in a semicolon:- if(expr) ...

XML problem with special characters like "<" and ">"
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag domElement = domDocument.createElement ("ROOT_TAG"); domDocument.appendChild (domElement); // XML from an external source as a "String" Text data = domDocument.createTextNode (externalXML); domElement.appendChild (data); writer.println (...); ------------------------------------------------------- As you can see, I create a normal Root-Node and then I get an XML stream from an external source....

Web resources about - How to get value of XML "Element " type node - comp.text.xml

Resources last updated: 3/14/2016 1:19:58 AM