How to get nodes and its attributes of an XML file usiong DOM parsing?

how to get nodes and its attributes of an XML file usiong DOM parsing?
i am new to XML parsing.......
Thanking you........

import org.w3c.dom.Document;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;      ...
//Setup the document
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
     Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
//get elemets by name
     String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
//This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

Similar Messages

  • How Adobe gets DATE and its format?

    Hello,
    I am getting current (todays) date by using below JS in some flds, and by using below FormCalc for some flds into my_form,
    JS:
    var currentTime = new Date()
    Form Calc:
    $.rawValue = num2date(date(), DateFmt(MM/DD/YYYY))
    But, i dont have much idea that how adobe is getting this date? For my company this is the very first form, hence they are asking me how adobe gets date and its format whether,
    1) From local IP/Interner provider address's date, format?
    2) or user PC/laptop's LOCAL settings date, format? if so, for example, if Germany user (Laptop settings) has a DD.MM.YYYY configured, if this user comes to US on a busines trip and if that user opens the form, then how the date looks like for this user? as per user laptop settings DD.MM.YYYY or local internat provider date format MM//DD//YYYY?
    Thank you

    Hi,
    the date() function returns the number of days since 01.01.1900 for the local date of the current system (related to the system clock of the OS).
    If you travel from Germany to the US but don't update your date/time settings, then it returns the same date in the US as in Germany.
    You can check the behavior by changing your local date/time setting or the timezones.

  • How to get Capacity And Custom Attribute Data Through Powershell

    how to get Capacity And Custom Attribute Data Through Powershell

    Hi Nitesh,
    Great command from Martin.
    Also find a article to configure the Quota:
    http://technet.microsoft.com/en-us/library/aa998353(v=exchg.141).aspx
    Thanks
    Mavis Huang
    TechNet Community Support

  • Getting links and its names from a html file

    Hi everyone
    My problem about the a getting links with name from a html file. For example
    İn a web page in this site ?SUN? when use click SUN the browser open http://java.sun.com
    İ want both of them, so the links and name. I can succeeded the get link but i don t know how to get the link name.
    For example :
    <B>setRightComponent(Component)</B>
    &#304;n this code segment i want to get B tag. But how i don t know. To get A tag i used this code
    List result = new ArrayList();
    try {
    // Create a reader on the HTML content
    URL url = new URI(uriStr).toURL();
    URLConnection conn = url.openConnection();
    Reader rd = new InputStreamReader(conn.getInputStream());
    // Parse the HTML
    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
    kit.read(rd, doc, 0);
    // Find all the A elements in the HTML document
    HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
    SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
    String link = (String)s.getAttribute(HTML.Attribute.HREF);
    if (link != null) {
    result.add(link);
    it.next();
    &#304; can use B tag but i don t know hot to get its value because it has no prefix such as HREF....
    i am sorry if i use a bad explanation style or incorrect word.

    import java.io.*;
    import java.net.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    class GetLinks
        public static void main(String[] args)
            throws Exception
            // Create a reader on the HTML content
            Reader reader = getReader( args[0] );
            // Parse the HTML
            EditorKit kit = new HTMLEditorKit();
            HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
            doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            kit.read(reader, doc, 0);
            // Find all the A elements in the HTML document
            HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
            while (it.isValid())
                SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
                String href = (String)s.getAttribute(HTML.Attribute.HREF);
                int start = it.getStartOffset();
                int end = it.getEndOffset();
                String text = doc.getText(start, end - start);
                System.out.println( href + " : " + text );
                it.next();
        // If 'uri' begins with "http:" treat as a URL,
        // otherwise, treat as a local file.
        static Reader getReader(String uri)
            throws IOException
            // Retrieve from Internet.
            if (uri.startsWith("http:"))
                URLConnection conn = new URL(uri).openConnection();
                return new InputStreamReader(conn.getInputStream());
            // Retrieve from file.
            else
                return new FileReader(uri);
    }

  • How to store ,retreive and edit  data from an xml file

    I am new to XML. I am creating a phone book in JSP with backend as an XML file.How can I store retrieve and edit datas from a jsp file.
    Please provide me with examples.I dont want to use bean.
    Please provide examples

    You will have to do some leg-work yourself. You will probably want to use DOM to parse and manipulate your XML data. Xerces (xml.apache.org) is a good open source parser. There are extensive examples on their site.
    - Saish

  • How to get Context paramters out of Tomcat web.xml file

    The Documentation at Tomcat seems to suggest:
    Context initialization parameters that define shared
    String constants used within your application, which
    can be customized by the system administrator who is
    installing your application. The values actually
    assigned to these parameters can be retrieved in a
    servlet or JSP page by calling:
    String value =
    getServletContext().getInitParameter("name");
    Now I want to write a jsp, where the user enters his username and pwd, and this contacts a jdbc connection bean. I want to store the driver name in the web.xml file. Now can some1 please suggest a method as to how I can extract this (It ain't that straightforward as suggested in tomcat doumntation. You cannnot call the above method ithout Servlet Initialization (actually to say ithout HTTP Connection). I succeeded when I had written a servlet, but can some1 please suggest an alternative (bcoz othrwise just to extract that I am writing a servlet).
    Hope I am clear.
    Thanks in advance.

    Edit your web.xml file and add these entries,
    <context-param>
    <param-name>dbUrl</param-name>
    <param-value>jdbc:oracle:thin:@server5:1521:pl2java</param-value>
    </context-param>
    <context-param>
    <param-name>dbDriver</param-name>
    <param-value>oracle.jdbc.driver.OracleDriver</param-value>
    </context-param>
    Place the above entries in between your already existing <web-app> and </web-app> tags.
    Now in your jsp, you can use, <% application.getInitParameter(); %> and in servlet, getServletContext().getInitParameter();
    Hope this helps.
    Sudha

  • How can I disable windows firewall and install cluster software and its service using unattended.xml file?

    platform: 2008r2
    services which need install: MSDTC Service, Windows Cluster Service, SQL Cluster

    Hi,
    I am not quiet understanding your question, could you clarify your question, as far as I know, an answer file is an XML-based file that contains setting definitions and values
    to use during Windows Setup. In an answer file, you specify various setup options, including how to partition disks, the location of the Windows image to install, and the product key to apply. You can also specify values that apply to the Windows installation,
    such as names of user accounts, display settings, and Internet Explorer favorites. The answer file for Setup is typically called Unattend.xml.
    The related KB:
    Building an Answer File
    http://technet.microsoft.com/en-us/library/cc748874(v=ws.10).aspx
    Hope this helps.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • How can I open and diplay the inhalt of  xml-file on a Jpanel

    It sounds very simple to do that. I've already read the Xml-tutorial. But I still don't know, how can I do it?what is the best and simple way to do that? Any advice would be greatly appreciated! Please write some code for me, if possible. so that I can grasp it ASAP!

    * Display_XML.java
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    public class Display_XML extends JFrame {
        public Display_XML() {
            initComponents();
            readXML();
        private void initComponents() {
            textScroller = new JScrollPane();
            textarea = new JTextArea();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setTitle("Alimentation:  product list");
            textarea.setEditable(false);
            textarea.setBackground(new Color(254,254,204));
            textScroller.setViewportView(textarea);
            getContentPane().add(textScroller, BorderLayout.CENTER);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    This example reads this XML data file [Alimentaion_Test_File.xml]
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <Alimentation>
         <Product>
              <Name>Milk</Name>
              <Price>1.50</Price>
         </Product>
         <Product>
              <Name>Cheese</Name>
              <Price>2.10</Price>
         </Product>
         <Product>
              <Name>Butter</Name>
              <Price>1.90</Price>
         </Product>
         <Product>
              <Name>Cream</Name>
              <Price>1.96</Price>
         </Product>
    </Alimentation>
        private void readXML() {
            File file = new File("Alimentaion_Test_File.xml");
            try {
                DocumentBuilder builder =
                        DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document doc = builder.parse(file);
                NodeList nodes = doc.getElementsByTagName("Product");
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element element = (Element) nodes.item(i);
                    NodeList title = element.getElementsByTagName("Name");
                    Element line = (Element) title.item(0);
                    textarea.append("Name: " + getCharacterDataFromElement(line)+"\n");
                    NodeList url = element.getElementsByTagName("Price");
                    line = (Element) url.item(0);
                    textarea.append("   Price: " + getCharacterDataFromElement(line)+"\n");
            } catch (Exception e) {
                e.printStackTrace();
        public static String getCharacterDataFromElement(Element e) {
            Node child = e.getFirstChild();
            if (child instanceof CharacterData) {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            return "?";
        public static void main(String args[]) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Display_XML().setVisible(true);
        private JScrollPane textScroller;
        private JTextArea textarea;
    }

  • [JS-CS4] - How to read the XML Element and its Attributes

    Dear All,
      I have the doubt regarding: reading the xmlElement and its attributes.
    Here I droping the xml script
    //============= Start ======================//
    var myDoc = app.activeDocument;
    var Fpath = File("../Projects/Entity_map.xml");
      if (Fpath.exists)
       Fpath.open("r");
       var Cont= Fpath.read();
      var roots = new XML(Cont);
      var myEveryName = new Array();
      var myEveryContent = new Array();
      var myEveryAttributes = new Array();
      traverse(roots);
    //$.writeln(myEveryName);
    //$.writeln(myEveryContent);
    $.writeln(myEveryAttributes.length);
    for(var i=0; i<myEveryAttributes.length; i++)
      $.writeln(myEveryAttributes[i]);
    function traverse(tree) {
        myEveryName.push(tree.name());
    myEveryContent.push(tree.text());
      myEveryAttributes.push(tree.getAttribute);
    // you get the contents by using .text() insted of .name()
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //============== End =====================//
    and the XML Structure is
    //===============XML =====================//
    <?xml version="1.0" encoding="UTF-8"?>< Entity_Convertion>
    < Entitys char="Ç" GID="173"/></ 
    Entity_Convertion>
    //===============End ====================//
    Here I'm getting the XML Elements and its contents, but not xmlAttributes.
    Please any one can help me, then I will appreciate...
    Thanks & Regards
    T.R.Harihara SudhaN

    Dear All,
      I have the doubt regarding: reading the xmlElement and its attributes.
    Here I droping the xml script
    //============= Start ======================//
    var myDoc = app.activeDocument;
    var Fpath = File("../Projects/Entity_map.xml");
      if (Fpath.exists)
       Fpath.open("r");
       var Cont= Fpath.read();
      var roots = new XML(Cont);
      var myEveryName = new Array();
      var myEveryContent = new Array();
      var myEveryAttributes = new Array();
      traverse(roots);
    //$.writeln(myEveryName);
    //$.writeln(myEveryContent);
    $.writeln(myEveryAttributes.length);
    for(var i=0; i<myEveryAttributes.length; i++)
      $.writeln(myEveryAttributes[i]);
    function traverse(tree) {
        myEveryName.push(tree.name());
    myEveryContent.push(tree.text());
      myEveryAttributes.push(tree.getAttribute);
    // you get the contents by using .text() insted of .name()
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //============== End =====================//
    and the XML Structure is
    //===============XML =====================//
    <?xml version="1.0" encoding="UTF-8"?>< Entity_Convertion>
    < Entitys char="Ç" GID="173"/></ 
    Entity_Convertion>
    //===============End ====================//
    Here I'm getting the XML Elements and its contents, but not xmlAttributes.
    Please any one can help me, then I will appreciate...
    Thanks & Regards
    T.R.Harihara SudhaN

  • My sister has the latest iphone 4 update and so do I. She has this feature that is like a shortcut on her screen at all times and I was wondering how I get it? Its like a square thats faded with a white circle around it?

    My sister has the latest iphone 4 update and so do I. She has this feature that is like a shortcut on her screen at all times and I was wondering how I get it? Its like a square thats faded with a white circle around it?

    Whereabouts on her screen at all times? What does it do?

  • JTextPane (reading char and its attributes)

    Hellow,
    I am trying to write a simple editor, where a person could write his text (in different size and color etc.) and than i need to turn this text to html code.
    So the way that i determen the shape of the text in JTextPane is:
    StyleConstants.setBold(set, false);
    *               pane.setCharacterAttributes(set, false);*
    And now i have to you trought the document and read the chars and its asstributes.
    And the way that i go trought the doc is by using the caret: moveCaretPosition(x);
    Reading the char: char c=pane.getText(pane.getCaretPosition(),1).charAt(0);
    But the problem now is... by moving the caret (dot) the mark stays in its place, so when I try to read the attribues(*AttributeSet crka;crka=pane.getCharacterAttributes();*), i read them for all the chars selected so far (0->x).
    How do i move this oround, so that only one char is read and its attributes?
    Edited by: Defero on Jul 19, 2008 3:09 AM

    Sorry for that,
    Yeah but it still doesnt work right.
    Example:
    Text in pane:
    AB C DEFGH... (ignore spacers)
    And then if i read the number of attributes on each char, they go like this:
    00111111...
    Just in case, i post my code of setting the arguments:
    JButton gumb=new JButton("bold");
            gumb.addActionListener((
                     new ActionListener() {
                         public void actionPerformed(ActionEvent e) {
                              if(bold==false){     
                            StyleConstants.setBold(set, true);
                           pane.setCharacterAttributes(set, true);
                           pane.requestFocus();
                          bold=true;
                              }else {
                                   StyleConstants.setBold(set, false);
                                   pane.setCharacterAttributes(set, false);
                                   bold=false;
                                   pane.requestFocus();
                 ));And reading should go like this right?:
    StyledDocument ddoc=pane.getStyledDocument();
    for(int i=0;i<ddoc.getLength();i++){
    int x=ddoc.getCharacterElement(i).getAttributes().getAttributeCount();
    }Edited by: Defero on Jul 19, 2008 10:12 PM
    Edited by: Defero on Jul 19, 2008 10:12 PM

  • Move node and its silings from one jtree to another

    Hi,
    I am trying to move JTree nodes and its siblings from one JTree to another. If anyone has the code, please post it on the website or mail to [email protected]
    Thanks
    Pavan

    Pavan,
    You may have to do a sanity check before adding it.
    Better run the program in a debugger and have a break point at the clipBoard.put() line. Else system.out.println() lines will kill enormouse programming time rather than using debugger.
    Also in following this thread, i found that you may have to be bit more thorough with the DefaultMutableTreeNode class first.
    Thanks,
    ananth
    Thomas,
    for (int p = 0; p < jtree.getSelectionCount(); p++) {
                   System.out.println(".3.......p= "+p);
    node =
    =
    (EuamDefaultMutableTreeNode)paths[p].getLastPathCompon
    nt();
                        clipBoard.put(node.toString(), node);
                   System.out.println(".4...........");
    Giving error at clipBoard.put()
    line....java.lang.NullPointerException
    ..Any idea why?
    Thanks.
    Pavan

  • How to get gui_download and gui_upload with popup filename?

    how to get gui_download and gui_upload with popup filename?

    Here is a short example.
    report zrich_0003 .
    data: ifiletab type filetable.
    data: xfiletab like line of ifiletab.
    data: xstring type string.
    data: rc type i.
    data: itab type table of string.
    data: xtab type string.
    start-of-selection.
      call method cl_gui_frontend_services=>file_open_dialog
        changing
          file_table              = ifiletab
          rc                      = rc.
      read table ifiletab into xfiletab index 1.
      xstring = xfiletab-filename.
      check not xstring is initial.
      call method cl_gui_frontend_services=>gui_upload
        exporting
          filename                = xstring
      changing
        data_tab                = itab.
      loop at itab into xtab.
        write:/ xtab.
      endloop.
    Regards,
    Rich Heilman

  • How to get vendor and company code based on logistic invoice document

    how to get vendor and company code based on logistic invoice document in abap/4?

    Hello Kumar
    When you call BAPI_INCOMINGINVOICE_GETDETAIL using
    INVOICENUMBER = <number of invoice>
    FISCALYEAR = <fiscal year>
    the returned HEADERDATA contains what you are looking for:
    HEADERDATA-COMP_CODE
    HEADERDATA-DIFF_INF
    Regards
      Uwe

  • How to get tools and other bars back in view after deleting show-bar?

    How to get tools and other bars back in view after deleting show-bar?

    Hello Jouko.
    You can go into View > Toolbars and select the ones you want to see. If you can't see the menu bar you can simply tab ALT on your keyboard (I think F10 works too) to show it.

Maybe you are looking for

  • Problem in java.io.file reading

    Hi I have a servlet and it calls some classes which are kept in a jar file in WEB-INF/lib directory. With in one of the classes there is a IO file read happening. How should i read the file and what path should i put if the file is in WEB-INF/resourc

  • Login in console denying the username?

    Hi there, some minutes ago i tried to login on one of my virtual consoles and did a small typo on the username. The reaction was quite surprising, maybe you get it when looking at the output: Arch Linux (Core Dump) 2.6.23-kamikaze (flusenfalle) fluse

  • Urgent: Add a custom line in Hierarchical ALV.

    Hi I am using the FM 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' to display the header and item table details.  However I would like to add a custom line below the item details of each section so that I can calculate the total (total of a particular field in th

  • Is it possible to access a database on a different  server?

    Hi Folks Forgive me if this has been asked already. We are in the process of moving one of our sites to a new server. It will reside there alone. I have several Access databases that are shared between two different websites. Now these sites will res

  • Partition Problem / Blank Screen

    So lets begin, ~I started boot camp assistance to install Windows XP Pro SP2. ~I partitioned 32 Gb as recommended for FAT. ~I followed directions and got to the point where the "Windows XP Professional Setup" screen asks you to select the partition ~