Newbie in XML

Hi All,
i have just started with java xml programming. I am trying to parse a simple document using DOM parser, and i have a few doubts.
My xml file is :
=========
<?xml version="1.0"?>
<personal_info>
<!-- This sample document contains my personal information-->
<name>
<fname>Ashish</fname>
<lname>Srivastava</lname>
</name>
<age>23</age>
<company>Oracle India Pvt. Ltd.</company>
<phone type="office">+91-40-55394676</phone>
<phone type="mobile">+91-40-32410638</phone>
</personal_info>
Parsing using DOM :
==============
public class DOM1{
public static void main(String args[]){
try
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("file:///e:\\java\\xml\\sample.xml");
Element root = doc.getDocumentElement();
System.out.println("Root name,value,type => "+root.getNodeName()+" -> "+root.getNodeValue()+" -> "+root.getNodeType());
for (Node child=root.getFirstChild();child != null; child=child.getNextSibling()){
int type=child.getNodeType();
System.out.println("Child name,val,type :- "+child.getNodeName()+" -> "+child.getNodeValue()+" -> "+child.getNodeType());
System.out.println("After Main");
}catch (Exception ex) {
System.out.println("Exception : "+ex); }
The o/p i get is :
===========
Root name,value,type => personal_info -> null -> 1
Child name,val,type :- #text ->
-> 3
Child name,val,type :- #comment -> This sample document contains my personal information -> 8
Child name,val,type :- #text ->
-> 3
Child name,val,type :- name -> null -> 1
Child name,val,type :- #text ->
-> 3
Child name,val,type :- age -> null -> 1
Child name,val,type :- #text ->
-> 3
Child name,val,type :- company -> null -> 1
Child name,val,type :- #text ->
-> 3
Child name,val,type :- phone -> null -> 1
Child name,val,type :- #text ->
-> 3
Child name,val,type :- phone -> null -> 1
Child name,val,type :- #text ->
-> 3
After Main
My question is :
* Where does the '#text' come from? It appears for all the nodes
* Why dont the actual value for a node get displayed? (like if nodeName is 'age' the value shud be '23', but is not displayed)?
Thanks in advance,
Ashish

#text nodes are the empty text nodes.
If the XML document is modified to remove space between the nodes, the #text nodes would not be generated.
For example XML document:
<personal_info><name><fname>Ashish</fname><lname>Srivastava</lname>
</name></personal_info>
would not generate #text nodes.
To obtain the value of the text in a node
Node node;
String nodeValue=node.getFirstChild().getNodeValue();

Similar Messages

  • Newbie question - XML version, searching by artist

    Probably quite a common problems - apologies for newbie questions.
    I've changed the URL of my MP3s in my XML to a new location and refreshed my feed. Is there a way of seeing what version of the XML iTunes is using? (it takes around 24 housr to refresh, right?)
    Also, when I'm searching for my podcast by author it's not coming up (<channel><itunes:author>) - is there a reason for this or a way to get it to show up when people search for the artist, other than doubling it in the title? (This works by the way, but I'd prefer not to!)
    Thanks.

    you can do it in just one loop, going through all the image
    tags in index_content and for each tag fill the values of all four
    arrays
    for (i...) {
    get the appropriate child of index_content
    first_array[ i ] = value of first tag
    second_array[ i ] = value of second tag
    no need for multiple loops.
    flash has functionality for xml files, but it helps to write
    a little wrapper around it, to simplify programming, especially if
    you work with xml a lot.. I wrote my for work, so I can't show it
    to you, but it's not very complicated to do

  • Newbie: Read XML data in Java

    Hello
    I am very new to Java and XML and I have some basic questions.
    I am creating some mailing lists in an XML tag where I have a identifier tag and then the e-mails as child tags. Something like this:
    <mail-list id="1" name="friends">
    <to-list id=1>
    <receiver id="1" address="[email protected]"/>
    <receiver id="2" address="[email protected]"/>
    </tolist>
    </mail-list>
    I would like to create a method that receives the name of the mail list (ex:friends) and returns all the e-mail addresses that it contains.
    How can I import data from a DOM to Java and return the text from a specific element or attribute?
    Thanks

    I would like to create a method that receives the name of the mail list (ex:friends) and returns all the e-mail addresses that it contains.You will need to traverse DOM document structure based on the filter //mail-list[@name="friends"] and then obtain each receiver id through nodelist object.
    How can I import data from a DOM to Java and return the text from a specific element or attribute?http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/TOC.html : This link has it all + contains examples to explain concepts.

  • XML newbie question - xml into arrays

    I am pretty new xml and I am working with a file that has
    text
    associated with images in the file and I would like to move
    the text
    into a xml document.
    I heard that a good way to deal with xml is to load it into
    an array. I
    have my text set up in arrays already, so my whole file
    aready works in
    that way. So all I have to do is load my xml document into my
    arrays. I
    have the xml document loading fine, but I don't know how to
    get the info
    into my arrays.
    My xml document looks like this:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <index_content>
    <image no="1">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 01"</title>
    <text>"Text bla bla, bla 01, Text bla bla, bla
    01"</text>
    <corner>"unisex"</corner>
    </image>
    <image no="2">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 02"</title>
    <text>"Text bla bla, bla 02, Text bla bla, bla
    02"</text>
    <corner>"men’s & women’s"</corner>
    </image>
    <image no="3">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 03"</title>
    <text>"Text bla bla, bla 03, Text bla bla, bla
    03"</text>
    <corner>"men’s & women’s"</corner>
    </image>
    <image no="4">
    <imgLink>"pages/collection.html"</imgLink>
    <title>"Title 04"</title>
    <text>"Text bla bla, bla 04, Text bla bla, bla
    04"</text>
    <corner>"men’s & women’s"</corner>
    </image>
    </index_content>
    My arrays in Flash are:
    var imgLinkURLs:Array = [];
    var imgTitles:Array = [];
    var imgTexts:Array = [];
    var imgCornerLabel:Array = [];
    So I think i need for loops pushing for example imgLink from
    image no1
    into imgLinkURLs array, then push imgLink from image no2, and
    so forth.
    Then do the same for imgTitle and the other arrays...
    How would I do this the right way?

    you can do it in just one loop, going through all the image
    tags in index_content and for each tag fill the values of all four
    arrays
    for (i...) {
    get the appropriate child of index_content
    first_array[ i ] = value of first tag
    second_array[ i ] = value of second tag
    no need for multiple loops.
    flash has functionality for xml files, but it helps to write
    a little wrapper around it, to simplify programming, especially if
    you work with xml a lot.. I wrote my for work, so I can't show it
    to you, but it's not very complicated to do

  • Newbie: Parsing XML data

    I have bunch of XML files and I want to develop a keyword based search engine which parses those XML files.
    Do you have any idea which is the best way to do the job? I mean on Linux? Should I use PHP? JAVA? Python??
    Please let me know. I am very new to everything in this domain.
    Thanks
    Dexter

    i am getting runtime error
    java.lang.NullPointerException
    at Employee.setdata(Employee.java)
    at Employee.actionPerformed(Employee.java)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow
    n Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  • Newbie - create xml to string

    I'm new to JAXP. I just want to use JAXP to create a DOM, then get the XML to use as a String in Java without any directives. Just a simple as possible like :
    <myelement>
    <myprop name="myname"/>
    </myelement>
    Is there some simple code I can use to do this? It can create the simple DOM using the code below, but how to I get the String value?
              javax.xml.parsers.DocumentBuilderFactory dfactory =
    javax.xml.parsers.DocumentBuilderFactory.newInstance();
              Node top = doc.createElement("myelement");
              top.appendChild(doc.createTextNode("child"));
              doc.appendChild(top);
    Thanks!

    Use a Transformer with a null xsl, and specify the target as a StringWriter

  • Newbie: Traversing XML with Java

    i have an xml file named contactlist.xml. The DTD is as follows:
    <!DOCTYPE contactlist [
    <!ELEMENT contactlist     (contact+)>
    <!ELEMENT contact     (name,tel,email)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT tel (#PCDATA)>
    <!ELEMENT email (#PCDATA)>
    ]>
    It is a well formed document. Now what i need to do is to use java to traverse this document when given a name to return the coresponding telephone number and email address. I have created a java file named TraverseContacts.java using DOM. I have been able to get access of the file contactlist.xml (document = builder.parse(new File("contactlist.xml"))) but i am being unable to traverse it! Here is an extract of the code which traverses the document:
    switch(node.getNodeType()){
                   //if its not a Document node, process its children
                   case Node.DOCUMENT_NODE:
                        Document doc= (Document) node;
                        getResult(doc.getDocumentElement());
                        break;
                   //process element node acording to its tag name
                   case Node.ELEMENT_NODE:
                        if(node.getNodeName().equals("contactlist"))
                             processChildNodes(node.getChildNodes());
                        else if(node.getNodeName().equals("contact"))
                             processChildNodes(node.getChildNodes());
                        else if(node.getNodeName().equals("name"))
                             //find the attribute value for name
                             //check whether it matches the query
                             NamedNodeMap nameAttributes=node.getAttributes();
                             Node value = nameAttributes.item(0);
                             if((value.getNodeValue()).equalsIgnoreCase(name)){
                                  if(node.getNodeName().equals("tel"))
                                       Element telElement = (Element) node;
                                       tel_no += telElement.getAttribute("tel");
                                       result += tel_no;
                                  if(node.getNodeName().equals("email"))
                                       Element emailElement = (Element) node;
                                       e_mail += emailElement.getAttribute("email");
                                       result += e_mail;
                             else return;
                        else if(node.getNodeName().equals("tel")){
                             Element telElement = (Element) node;
                             tel_no += telElement.getAttribute("tel");
                             result += tel_no;
                        else if(node.getNodeName().equals("email")){
                             Element emailElement = (Element) node;
                             e_mail += emailElement.getAttribute("email");
                             result += e_mail;
                        break;
    can somebody please tell me where have i gone wrong. i am sure the mistake is somewhere around here in this java code only but am unable to identify it.

    Your DTD indicates that you have (for eaxample) an email element with text in it but no attributes, but you are using emailElement.getAttribute("email"). You need to get the string value of the text node(s) within emailElement, not the attribute value.
    Pete

  • NEWBIE: AS3/XML DataGrid Component interaction

    So heres the situation:
    I'm trying to create a simple newsreader using a Flash
    DataGrid component in which data is loaded via EXTERNAL XML
    attributes. And it works fine...got 2 columns, "subject" and "date
    posted", and the appropriate data being sent to the right place.
    So heres the problem:
    I'd like to link those rows, when the user clicks on any
    individual row, to load the "URL" attribute that the XML has
    defined. Feels like there's an easy solution but i just can't put
    my finger on it:
    Is this possible? Code below:
    < LexHead />

    Whay are you using a different formatted xml for the dummy
    than the real data. Using internal data for testing is a fine
    technique, but i needs to be the same format as the real data.
    Otherwise how will you know when you get the code right?
    I have an example that uses HTTPService to get an xml file
    from the server, uses a tree to display/edit the nodes, a dynamic
    dataGrid for displaying/editing the attributes, and HTTPService to
    send it back to the server. The backend is JSP, so to run that
    you'd need a J2EE web server like Tomcat, but the tree and property
    explorer might be useful.
    Semd me an email and I will send it to you directly.
    Tracy

  • Newbie at XML

    Hi,
    i am suppose to be able to dynamically retrieve string variables into an XML document...but i don't have any idea of how to go about it......
    thanks.....some codes perhaps???

    Check this: http://java.sun.com/xml/javaxmlpack.html
    You should find what you are looking for
    Hope this helps,
    Manuel

  • Newbie - XML File - How to load data and populate tables

    Hi,
    I'm newbie to XML data handling.
    I have a file that is provided in XML format with data from an external system.
    I need to load data from that file and populate some field in one or more tables.
    I have two options:
    1. Load the XML file directly from OS and populate the tables directly (I'm not sure if this is possible or not)
    2. Load the entire XML file from OS into a CLOB or a BLOB(?) and the select the data form the CLOB and populate my tables.
    I need some guidance about what is possible and how to do it.
    My preferred approach if possible is to load the data directly from OS and populate the target tables without loading into the database previously.
    Thanks for the help.
    Tech Info:
    OS : Unix / Windows
    DB Version: 11.2 or 11.1
    JF

    forum has many examples
    use search
    as example see
    Re: Load xml data in Oracle table
    Re: Load an XML file into table(s)
    Re: load a file

  • Formatting Text - XML newbie wants everything!

    Greetings Folks
    I am a newbie to this Forum and a relatively newbie to XML.
    As usual I want to know everything and do everything . . .
    and I want it now! Just kidding!
    Here is my first challenge with code following:
    Can I add tags to "text" in my .xml file so that I can have
    bold, italic, underline and link info embedded when using an .xsl
    stylesheet to format same?
    Here is my sample .xml file called "demo.xml" produced using
    DW8:
    quote:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <?xml-stylesheet href="demo.xsl" type="text/xsl"?>
    <demo>
    <text>
    <start>The quick brown fox</start>
    <finish>jumps over the lazy dog</finish>
    </text>
    </demo>
    And here is my .xsl file called "demo.xsl":
    quote:
    <?xml version="1.0" encoding="iso-8859-1"?><!--
    DWXMLSource="demo.xml" --><!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp " ">
    <!ENTITY copy "©">
    <!ENTITY reg "®">
    <!ENTITY trade "™">
    <!ENTITY mdash "—">
    <!ENTITY ldquo "“">
    <!ENTITY rdquo "”">
    <!ENTITY pound "£">
    <!ENTITY yen "¥">
    <!ENTITY euro "€">
    ]>
    <xsl:stylesheet version="1.0" xmlnssl="
    http://www.w3.org/1999/XSL/Transform">
    <xsl
    utput method="html" encoding="iso-8859-1"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="<A href="
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/">http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd"/>
    <xsl:template match="/">
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1"/>
    <title>Untitled Document</title>
    </head>
    <body><table width="300" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td><div align="right"><xsl:value-of
    select="demo/text/start"/></div></td>
    <td> <xsl:value-of
    select="demo/text/finish"/></td>
    </tr>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    By asking IE or Firefox to display demo.xml I get the
    following result:
    The quick brown fox jumps over the lazy dog.
    Challenge: Can I have it rendered like this -
    The quick
    brown
    fox jumps
    over the
    lazy dog
    If lazy dog can be made a hyperlink as well then I would say
    XML really "ROCKS".
    The 2nd challenge is:
    Can I have a lengthy passage of text and be able to assign
    paragraph breaks so the browser will display sentences in
    paragraphs? (I trust this does not need an example and my request
    is self explanitory)
    If you can help me, with say a working example, I would be so
    appreciative.
    Thanks in anticipation
    AceTutor

    Odd quesiton but why are you doing it like this ?
    XHTML sounds like what you want ...
    Anyhow, you can do all you want - but its a little more
    complicated - and
    hard to explain here - you need to explicitly state how they
    should appear,
    within your XSLT ... (I Think, never having done it)
    G
    "AceTutor@Warwick" <[email protected]> wrote
    in message
    news:[email protected]...
    > Greetings Folks
    >
    > I am a newbie to this Forum and a relatively newbie to
    XML.
    > As usual I want to know everything and do everything . .
    . and I want it
    > now!
    > Just kidding!
    >
    > Here is my first challenge with code following:
    > Can I add tags to "text" in my .xml file so that I can
    have bold, italic,
    > underline and link info embedded when using an .xsl
    stylesheet to format
    > same?
    >
    >
    > Here is my sample .xml file called "demo.xml" produced
    using DW8:
    >
    > <blockquote>quote:<br><hr><?xml
    version="1.0" encoding="iso-8859-1"?>
    > <?xml-stylesheet href="demo.xsl" type="text/xsl"?>
    > <demo>
    > <text>
    > <start>The quick brown fox</start>
    > <finish>jumps over the lazy dog</finish>
    > </text>
    > </demo>
    > <hr></blockquote>
    >
    > And here is my .xsl file called "demo.xsl":
    >
    > <blockquote>quote:<br><hr><?xml
    version="1.0" encoding="iso-8859-1"?><!--
    > DWXMLSource="demo.xml" --><!DOCTYPE xsl:stylesheet
    > <!ENTITY nbsp " ">
    > <!ENTITY copy "?">
    > <!ENTITY reg "?">
    > <!ENTITY trade "?">
    > <!ENTITY mdash "?">
    > <!ENTITY ldquo "?">
    > <!ENTITY rdquo "?">
    > <!ENTITY pound "?">
    > <!ENTITY yen "?">
    > <!ENTITY euro "?">
    > ]>
    > <xsl:stylesheet version="1.0" xmlnssl="<a
    target=_blank
    > class=ftalternatingbarlinklarge
    > href="
    http://www.w3.org/1999/XSL/Transform">
    > <xsl
    utput">
    http://www.w3.org/1999/XSL/Transform">
    > <xsl
    utput</a> method="html" encoding="iso-8859-1"
    > doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="<A
    > href="<a target=_blank
    class=ftalternatingbarlinklarge
    > href="
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/">http://www.w3.o
    > rg/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
    >
    > <xsl:template">
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/">http:/
    > /www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
    > <xsl:template</a> match="/">
    > <html xmlns="<a target=_blank
    class=ftalternatingbarlinklarge
    > href="
    http://www.w3.org/1999/xhtml">
    > <head>
    > <meta">
    http://www.w3.org/1999/xhtml">
    > <head>
    > <meta</a> http-equiv="Content-Type"
    content="text/html;
    > charset=iso-8859-1"/>
    > <title>Untitled Document</title>
    > </head>
    > <body><table width="300" border="0"
    cellspacing="0" cellpadding="0">
    > <tr>
    > <td><div align="right"><xsl:value-of
    select="demo/text/start"/></div></td>
    > <td> <xsl:value-of
    select="demo/text/finish"/></td>
    > </tr>
    > </table>
    > </body>
    > </html>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    >
    >
    > By asking IE or Firefox to display demo.xml I get the
    following result:
    >
    >
    > The quick brown fox jumps over the lazy dog.
    >
    >
    > Challenge: Can I have it rendered like this -
    >
    > The quick <b>brown</b>
    <u>fox</u> jumps <i>over</i> the <a
    target=_blank
    > class=ftalternatingbarlinklarge href="
    http://www.google.com">lazy
    dog</a>
    >
    > If lazy dog can be made a hyperlink as well then I would
    say XML really
    > "ROCKS".
    >
    >
    > The 2nd challenge is:
    > Can I have a lengthy passage of text and be able to
    assign paragraph
    > breaks so
    > the browser will display sentences in paragraphs? (I
    trust this does not
    > need
    > an example and my request is self explanitory)
    >
    >
    > If you can help me, with say a working example, I would
    be so
    > appreciative.
    >
    > Thanks in anticipation
    >
    >
    > AceTutor
    >
    >

  • How to read the content in one node of XML in Java? Pls help

    My dear brothers,
    I am a newbie of XML, I have a exercise which is creating a Tree View from XML file. But the trouble is I do not know how to read the content in one node of XML file. I decide to use the algorithm as following:
    1. Create a GUI form which gives the ability for user to choose a XML file (ok)
    2. Load XML and return the file (ok)
    3. Read the file from node to node to create the node in Tree View (?!)
    Please help me, and if you are enough kind, please give me an small example to easy understand. Thanks in advance.
    Hoang Yen Binh

    I hope this one helps you.
         <ABC Type="ProductBased" ProdName="One" Location="India">
              <CEO>Raj</CEO>
              <Finance>Vikram</Finance>
              <HR>Karthik</HR>
              <Technical>Satish</Technical>
         </ABC>
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Attr;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import org.w3c.dom.DOMException;
    import javax.xml.parsers.ParserConfigurationException;
    import org.xml.sax.SAXException;
    import java.io.File;
    import java.io.IOException;
    public class XmlReading {
         Document doc;
         Element element;
         public static void main(String[] args) throws Exception{
              XmlReading xr = new XmlReading();
              xr.getXmlParser(args);
         public void getXmlParser(String[] args) {
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   if(args.length != 1) {
                        System.err.println("Argument Required");
              try {
                   DocumentBuilder builder = factory.newDocumentBuilder();
                   doc = builder.parse(new File(args[0]));
              }catch(ParserConfigurationException e1) {
              }catch(SAXException e2) {
              }catch(IOException e3) {
              getAttributes();
         public void getAttributes() {
              // Retrive the entire Document from the Dom Tree
              element = doc.getDocumentElement();
    //          System.out.println(element);
              NamedNodeMap attrs = element.getAttributes();
              // Get number of attributes in the element
         int numAttrs = attrs.getLength();
         // Process each attribute
              for (int i=0; i<numAttrs; i++) {
                   Node node = attrs.item(i);
                   // Get attribute name and value
                   String attrName = node.getNodeName();
                   String attrValue = node.getNodeValue();
                   System.out.println(attrName + ": " + attrValue);
              String s1 = element.getTagName();
              System.out.println(s1);
              // To get all the elements in a DOM Tree
              NodeList nl1 = element.getElementsByTagName("*");
              int i2 = nl1.getLength();
              System.out.println(i2);
              for(int i=0; i<i2; i++) {
                   System.out.println(nl1.item(i) + "\n");
    }

  • Xml sax parser

    Hi all,
    I am newbie to xml. I am using SAX parser for parsing xml documents. I have to write a code which parses all types of xsd files(including which can contain inline , referenced or both). Can anyone help / guide me how to code a generic xsd parser??
    Thanks in advance,

    An XSD file is an XML file, so you can parse it using sax.
    See :
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
    See also:
    http://www.oracle.com/technology/tech/xml/xdk/doc/production/java/doc/java/javadoc/oracle/xml/parser/schema/XMLSchema.html#getXMLSchemaNodeTable

  • Creation of XML

    Till now i was working on my test server and creation of XML file seemed to be ok.
    Now i shifted to live server and suddenly XML creation is a problem. I do not have write access problem as the file is getting created and also root element is getting created. But after root nothing is going inside the file.
    I do not understand why suddenly server is behaving like this, but can anybody give clues ? Is there any settings required ?
    I am on Tomcat 5/Struts framework and using DOM to create file.
    regards
    Manisha

    i am a newbie in xml
    I want to know how to crate xml that takes value
    from the application
    Waiting for your reply
    thanking u
    take care
    byeAre you talking about saving objects to XML files?
    That can easily be done with XMLEncoder and XMLDecoder. Useful when you're too lazy to write a class to input and output to binary files... Like me :D

  • Need help in displaying XML in JSP

    Hi there,
    i'm a newbi in XML and Java - I have the following prob, think for most of u nothing very difficult (or better thought so, I've posted this question in different forums here, but nobody answers :)
    I get an XML response from a search engine, now I want to display the search result in a jsp.
    The result is stored in the session [I hope I figured out correctly ;)]
    with the following command ->
    this.pageContext.getSession().setAttribute(SEARCHRESULT, dSearchResult);
    [its from the java class, which generates the result]
    Result example ->
    <?xml version="1.0" encoding="UTF-8"?>
    <FindSearchResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xml/SearchResult.xsd">
    <Result Hits="2" Name="OfficeLand_en_US">
    <Items>
    <Item Score="250">
    <Field FieldNo="0" Name="ProductID">KqvAqAB1Tq0AAADnFthtpZvC</Field>
    <Field FieldNo="1" Name="CatalogCategoryID">gh0KAAFvj3wAAADiW8SMtr6o</Field>
    </Item>
    <Item Score="250">
    <Field FieldNo="0" Name="ProductID">4rwKAAFvtNYAAADiwdCMtr6o</Field>
    <Field FieldNo="1" Name="CatalogCategoryID">gh0KAAFvj3wAAADiW8SMtr6o</Field>
    </Item>
    </Items>
    <HitDistribution>
    <Hit Hits="75" Score="0"/>
    <Hit Hits="2" Score="250"/>
    </HitDistribution>
    </Result>
    </FindSearchResult>
    How many 'Field' elements exist, depends on the query.
    The result example is a response, which is send to my JSP page. It is stored in an variable under the name SEARCHRESULT (it's the result of a query in a search engine).
    My JSP page is the page, which should display the searchresult.
    So i need to know, how to programm something in my JSP page to check the SEARCHRESULT to display not the whole xml file. I just want to display all Items (compare with result example) -> The name of each existing FieldNo, the Score and the HitDistribution.
    Please help me :)

    hi there,
    first create a xml schema for the xml you will be receiving.
    use jaxb or castor with the schema and create a class.
    in your jsp unmarshal the xml result you are getting with the class
    generated by either jaxb or castor. the class will have methods that return you the required elements.
    get to know xml schema better and just a pass thru of jaxb or castor will solve the problem.
    vedha_g

Maybe you are looking for

  • Problems with programming submit button and attachment upload

    i have a problem programming the upload "athachments" and i would like to know how to program the submit button to go to an email address. once the form is filled out i want the information to go into my email inbox. what script or coding to i need t

  • My iPod froze! Not the kind of restarting freeze.... it's stuck on a video

    The screen is stuck onto the same image from a movie, no commands work, If I connect it to my computer, it does nothing, commands are still stuck it doesn't seem to work anymore

  • Blury photos and titles

    I have just started my first project and noticed that both the photos I import ( hi res jpegs ) from I photo and my pages in IMoive with just text are blury. When I checked the photos in Iphoto they are blury for a quick second and then clear up. I e

  • IDOC for Partial payments

    hi guys,         Kindly let me know if there is any IDOC for partial payments.  when you run f-53 With Reagards Pradeep N

  • Composite Primary Key question

    I have a new question regarding composite primary keys on another table I have created. I have the following table with the following definition: CREATE TABLE "APSOM"."CPULIST" ( "CPU_ID" VARCHAR2(10 BYTE), "SERVER_ID" VARCHAR2(10 BYTE), "CREATED_DAT