How can I get content of  xml elements?

Hello everybody,
here is my xml document and my code which parses xml. I want to print content of all elements from xml to console but result is only null. But names of all elements shows correctly. Where is problem? Thank you in advance
XMLSample.java
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class XMLSample {
     private void getAttribute(Document doc) {
NodeList list = doc.getElementsByTagName("*");
for (int i=0; i<list.getLength(); i++) {
// Get element
Element el = (Element)list.item(i);
System.out.println(el.getNodeName());
System.out.println(el.getNodeValue());
     private Document executeXML(String[]argv) {
          if (argv.length != 1) {
               System.err.println("Usage: java DomEcho filename");
               System.exit(1);
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          Document doc = null;
          try {
               DocumentBuilder builder = factory.newDocumentBuilder();
               doc = builder.parse(new File(argv[0]));                         
          } catch (SAXException sxe) {
               // Error generated during parsing)
               Exception x = sxe;
               if (sxe.getException() != null)
                    x = sxe.getException();
               x.printStackTrace();
          } catch (ParserConfigurationException pce) {
               // Parser with specified options can't be built
               pce.printStackTrace();
          } catch (IOException ioe) {
               // I/O error
               ioe.printStackTrace();
          System.out.println("doc > " + doc);
          return doc;
     public static void main(String argv[]) {
          XMLSample dom = new XMLSample();
          Document doc = dom.executeXML(argv);
          dom.getAttribute(doc);
library.xml
<library>
<book>
<author>
Jan Zitniak
</author>
<title>
JSP Guru
</title>
</book>
<book>
<author>
Jan Zitniak
</author>
<title>
JSP Guru
</title>
</book>
</library>

If you have XML like:
<target>value</target>What you actually have in DOM is:
Element
   TextCall getFirstChild() on the Element and cast the result as Text. Then call getNodeValue() on the Text node.
- Saish

Similar Messages

  • How can we get  tag of XML file using SAX

    Hi ,
    I'm parsing one SAX parser , I'have almost done this parsing. i have faced problem for one case, i'e how can we get tag from XML file using SAX parser?
    XML file is
    <DFProperties>
    <AccessType>
    <Get/>
    </AccessType> <Description>
    gdhhd
    </Description>
    <DFFormat>
    <chr/>
    </DFFormat>
    <Scope>
    <Permanent/>
    </Scope>
    <DFTitle>gsgd</DFTitle>
    <DFType>
    <MIME>text/plain</MIME>
    </DFType>
    </DFProperties>
    I want out like GET and Permanent... means this one tag which is present inside of another tag.
    Handler class like
    public void startElement(String namespaceURI, String localName,
                   String qName, Attributes atts) throws SAXException {
    if(_ACCESSTYPE.equals(localName)){
                   accessTypeElement=ACCESSTYPE;
    public void characters(char[] ch, int start, int length)
                   throws SAXException {
    if (_ACCESSTYPE.equals(_accessTypeElement)) {
                   String strValue = new String(ch, start, length);
                   System.out.println("Accestype-----------------------------> " + strValue);
                   //System.out.println(" " + strValue);
    public void endElement(String namespaceURI, String localName, String qName)
                   throws SAXException {
    if (_ACCESSTYPE.equals(localName)) {
                   _accessTypeElement = "";
    . please any body help me

    Hi ,
    I have one problem,Please help me.
    1. How can I'll identify where exactly my Node is ended,means how how can we find corresponding nodename? in partcular place
    <Node> .............starttag1
    <NodeName>Test</NodeName>
    <Node>................starttag2
    <nodeName>test1</NodeName>
    </Node>..................endtag2
    <Node>.....................starttag3
    <NodeName><NodeName>
    <Node> .........................starttag4
    <NodeName>test4</NodeName>
    </Node>.......enddtag4
    </Node>...........end tag3
    </Node>............endtag1
    my code is below
    private final String _NODENAME = "NodeName";
    private final String _NODE = "Node";
    private String _nodeElement = "";
         private String _NodeNameElement = "";
    public void startElement(String namespaceURI, String localName,
                   String qName, Attributes atts) throws SAXException {
    if (_NODENAME.equals(localName)) {
                   NodeNameElement = NODENAME;
    if(_NODE.equals(localName)){
         System.out.println("start");
         if (_NODENAME.equals(localName)) {
                   NodeNameElement = NODENAME;
    public void characters(char[] ch, int start, int length)
                   throws SAXException {
    if (_NODENAME.equals(_NodeNameElement)) {
                   String strValue = new String(ch, start, length);
                   String sttt=strValue;
                   System.out.println("NODENAME: ************* " + strValue);
    if(_NODE.equals(_nodeElement)){
                   if (_NODENAME.equals(_NodeNameElement)) {
                        String strValue = new String(ch, start, length);
                        String sttt=strValue;
                        System.out.println("nodevalue********** " + strValue);
    public void endElement(String namespaceURI, String localName, String qName)
                   throws SAXException {
    if (_NODENAME.equals(localName)) {
                   _NodeNameElement = "";
    if(_NODE.equals(localName)){
                   System.out.println("NODENAME: %%%%%%%%%");
    please help me. How can I figure node ending for particular nodename

  • How can I get the directory.xml file for WL6.0?

    I have installed the ALBPM Enterprise WL6.01 and started it in my server.But I get the error message when I login.
    directory configuration runtime fails to initilize with
    resource:/Aqualogic/j2eewl/tomcate/webapps/../../webapps/webconsole/WEB-INF/directory.xml
    How can I get the XML file?

    aaa, ok i misunderstood your first post, i thought you are talking about unable to use the directory.xml from your application.
    Ok, well the directory.xml file that ALBPM uses is allways in /albpm6.0/j2eewl/conf/directory.xml if we are not talking about Standalone. And when you start your albpm server it picks up the directory.xml file from there. But it picks him up only when you start it...so if you made any changes to it, you have to restart the server.
    You should check the instalation folder of your ALBPM.
    If you want to change the user/pass in the directory.xml change it in that folder and restart ALBPM.
    If you don't know how to enter new password you have to use this sintax:
    <encrypt>newPassword</encrypt>
    Because if you open the xml file you have only <encrypted> tags, and you can't change those.
    I don't know what the xml file is doing in that tomcat folder though...maybe it get's copied to that location when you start the albpm WL
    Hope this helps
    Edited by Lex_ at 12/13/2007 10:27 PM

  • How can I get content saved on iCloud on my iPhone?

    How do you get content saved on iCloud on your iPhone?

    Thanks! But I've already done that. But even when the syncing is on, it doesn't show on my iPhone. For example, I have 4,1 GB with pictures saved on iCloud, but I can't see any of them on my phone

  • How can I get content aware plugin for cs4

    How can I get fill> content aware plugin for cs4

    You can't. Features from new versions require you to buy the new version.

  • How can I get a file path element in XML to work in AI javascript?

    Hi all - this is my first post. I'm pretty familiar with javascript, but I'm new to the Adobe scripting environment.
    Our client wants Illustrator at startup to load a certain pattern swatch. It works fine when I hard code the pattern file path, but it needs to be user configurable, so I put the file path info in an XML file to be read in at startup. The XML file is read in and the elements are extracted into varibles. When I concatenate the variables to create the file path string and try to open the pattern file, it says file not found.
    Here is my source code:
    var fileObj = new File("aiConfig.xml");
    fileObj.open("r:");
    var xmlString = new XML(fileObj.read());
    var driveLetter = xmlString.fullPathName.driveLetter.text();
    var filePath = xmlString.fullPathName.filePath.text();
    var fileName = xmlString.fullPathName.fileName.text();
    var fullFilePath = driveLetter + filePath + fileName;
    var styled_ai = app.open(new File(fullFilePath));
    app.activeDocument = styled_ai;
    Here is aiConfig.xml:
    <?xml version="1.0" encoding="windows-1252" ?>
    <aiConfig>
      <fullPathName>
         <driveLetter>C:</driveLetter>
         <filePath>/Program Files/Adobe/Adobe Illustrator CS4/Presets/en_US/Swatches/Patterns/Decorative/</filePath>
         <fileName>Decorative_Modern.ai</fileName>
        </fullPathName>
    </aiConfig>
    Any help would be greatly appreciated - this is driving me a little crazy.
    Thanks,
    Tom

    Hi Tomchag,
    Your script works fine on MAC OS X & illustrator CS4.
    i have change only pathway to aiConfig.xml like this:
    var fileObj = new File("/Volumes/LaCie/aiConfig.xml"); //<- path of my external HDD should be D:/ on windows
    and the contents in aiConfig.xml to :
    <?xml version="1.0" encoding="windows-1252" ?>
    <aiConfig>
      <fullPathName>
         <driveLetter></driveLetter>
         <filePath>/Applications/Adobe Illustrator CS4/Presets.localized/fr_FR/Nuancier/</filePath>
         <fileName>VisiBone2.ai</fileName>
        </fullPathName>
    </aiConfig>
    So.. i notice twice thing:
    1) complete file and path for aiConfig.xml
    2) i didn't use drive letter (but it's specific to windows)
    I hope this post can help you
    Cyao, art.chrome

  • How can i get content library

    i can't add text because i don't have content library but i don't know how to get it.

    I have only been running iTunes for a very short time, so it was not backed up.   I know my library is toast.   I can recreate that.   But I should still be able to recover my purchased songs.   There is only music involved, no movies or other media.   Still have an answer?  Thanks.

  • How can I get through this Adobe Elements 9 error message

    It's been perfectly installed and I'm using a serial number. Everytime I try to go to an old project or create a new one it says "Sorry, a serious error has occured that requires Adobe Premiere Elements to shut down. We will attempt to save your current project." The full layout can't even show because of this. It's just a grey screen and you cannot access the options on the bar they are non clickable expect for New, Open Project, Recent Project, or exit. It's very annoying and I can't even do anything because of this..Does anyone have any solutions or has encountered this? I'm running on a Dell Inspiron which came with the double disk of this and Photoshop Elements 9 which I have no problems with whatsoever.

    Hi Oppositeofhood,
    Welcome to Adobe Forums.
    Please navigate to the below path and rename the syles folder to styles.old
    For Windows: C:\Users\bahl\Documents\Adobe\Premiere Elements\9.0
    For mac: Open the finder, go to documents>Adobe>Premiere Elements\9.0
    Then try to re-launch Premiere Elements and check if the issue persists.
    Thanks

  • How can I get the Organizer in Elements 12to display the file name and date of the thumbnail images?

    The View menu option to display the File Name is grayed out and thus I cannot display the file name.

    Hi,
    You need to go to View menu and check Details as well.
    You may even have to make the thumbnails larger by using the zoom slider at the bottom
    Good luck
    Brian

  • How can I get the Attribute Value in the existing XML Elements-Reg.

    Dear All,<br /><br />  I have the InDesign Document with xml Based, now I want to get the XML Elements name and XML Attributes for each Elements, using SDK Concepts. <br /><br />Example:<br /><br /> <chapter>  chapter1 </chapter> id = "ch001"<br /> <sec> Section ....</sec> id ="se001"<br /> <para> para ....</para> id="pa001"<br /><br />How can I get the XMLElements & XML Attributes in the InDesign-XML Structure.<br /><br />Please  any one can suggest me....<br /><br />Thanks & Regards<br />T.R.Harihara SudhaN

    Dear Dirk
    Many Thanks for the Suggestions, Now I search and study the XML concepts. Meanwhile, I need your suggestions for further Development in SDK -XML concepts.
    I am using the SnippetRunner -SDK file, their given some XML based programmes. [Create XML Elements, Elements + Attributes, XML Comments] and etc...
    Hope U will help me to Develop the SDK- XML Concepts.
    Thanks & Regards
    T.R.Harihara SuduhaN

  • How do I get content from my iPad to show up on the tv screen using Apple TV without going thru iTunes?

    How can I get content from my iPad and my air book to show up on the tv screen using Apple TV, without going thru iTunes?

    You will need to use AirPlay to see that.
    Assuming both devices are on the same network and that AirPlay is not turned off on the Apple TV, then simply tap on the screen when you are watching content you wish to stream to your Apple TV, then tap the airplay icon that appears in the control bar, choose the Apple TV from the menu that appears.
    When displaying the content you wish to mirror on the iPad 2 (or better), iPad Mini, iPhone 4S (or better), double tap the home button (quickly) and swipe the bottom row of apps to the right to reveal the playback controls, tap the AirPlay icon and select your Apple TV from the list of available devices.

  • How can I get the content of a text element to insert in a different block

    I have two blocks. The first one (block_control) is a non based block with a text element (EXERCICE). When I go to the second block (block_data) and I want to insert a new record, I need in my record the value of EXERCICE who is in the first block (block_control). How can I get this balue if I want to be able to do an execute_query too on the second block ? Because if I use pre-block or post-block or when-new-record-instance trigger to make the content of EXERCICE follow from block_control to block_data in a hidden field, I can't execute_query.
    Thank's

    First , when you want to insert a record in the second block , override the default commit_form processing and create a commit-form trigger which is called by a button to commit your form. The when-button-pressed trigger of this button should be : do_key('commit_form'); . And you create the key-commit trigger on the second block. Inside the key-commit trigger write this :
    :second_block.item_name := name_in('block_control_name.exercice');
    commit_form;
    In this way you get the exercice data into your record.
    Secondly, in the post-query trigger of the second block, set the exercice column of the second block to the exercice column of the block_control.
    And that's it.

  • I am new in indesign scripting, please tell me how to write a script to get  content of a element in xml and then sort all the content

    I am new in indesign scripting, please tell me how to write a script to get  content of a element in xml and then sort all the content

    Hi,
    May the below code is useful for you, but I dont know how to sort.
    Edit the tag as per your job request.
    alert(app.activeDocument.xmlElements[0].contents)
    //Second alert
    var xe = app.activeDocument.xmlElements[0].evaluateXPathExpression("//marginalnote");
    alert(xe.length)
    for(i=0; i<xe.length; i++)
        alert(xe[i].texts[0].contents)
    Regards
    Siraj

  • How can I get the XML structure from a flat structure?

    Hi all,
    in my XI SP 12 I use a JMS adapter to read information using the WebSphereMQ transport protocol.
    The structure that I receive have this format:
    <Name_A.KeyFieldValue><Name_A.fieldName_A1_Value>...<Name_A.fieldName_AN_Value>
    <NumberRecordType_B><NumberRecordType_c>
    <Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value>
    <Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value>
    <Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>
    <Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>
    the problem is that in this structure each line is not separated by a carriage return or a comma, I have all the information in a single line:
    <Name_A.KeyFieldValue><Name_A.fieldName_A1_Value>...<Name_A.fieldName_AN_Value><NumberRecordType_B><NumberRecordType_c><Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value>...<Name_B.KeyFieldValue><Name_B.fieldName_B1_Value>...<Name_B.fieldName_BN_Value><Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>...<Name_C.KeyFieldValue><Name_C.fieldName_C1_Value>...<Name_C.fieldName_CN_Value>
    and the customer don't want to insert a line separator.
    Then, the question is:
    How can I get the XML structure from this structure?
    If possible, I don't want to develop new Module and add it in the JMS Module Sequence.
    PS I have already read the article "How to Use the Content Conversion Module with the XI 3 J2EE JMS Adapter.pdf" and it doesn't seem to help me.
    Best Regards,
    Paolo

    To get context parameters from your web.xml file you can simply get the ActionServlet object from an implementing action object class. In the perform (or execute) method make the following call.
    ServletContext context = getServlet().getServletContext();
    String tempContextVar =
    context.getInitParameter("<your context param >");

  • How can I get xml data from KM?

    Hi guys,
    how can i get a xml data from KM?
    I saved an xml document in KM, and I want to read its content. How can I get this document?
    Using
    DocResource = (IResource) resFactory.getResource(RID.getRID("Document/ Path"),resContext)?
    I want to know which kinds of API of KM are responsible for this.
    Thanks in advance
    Regards,
    Liying

    Hi Liying
    use this code.
    try {
                   IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
                   IUser sapUser = wdClientUser.getSAPUser();
                   com.sapportals.portal.security.usermanagement.IUser ep5User =
                        WPUMFactory.getUserFactory().getEP5User(sapUser);
                   IResourceContext resourseContext = new ResourceContext(ep5User);
                   IResourceFactory resourseFactory = ResourceFactory.getInstance();
                   RID pathRID =
                        RID.getRID(
                             "/documents/"(Path to folder where ur file is"");
                   ICollection collection =
                        (ICollection) resourseFactory.getResource(
                             pathRID,
                             resourseContext);
                   IResourceList resourceList = collection.getChildren();
                   IResourceListIterator resourceListIterator =
                        resourceList.listIterator();
    while (resourceListIterator.hasNext()) {
                        com.sapportals.wcm.repository.IResource resource =
                             resourceListIterator.next();
    try {
                             /*File from KM Reading*/
                             InputStream in = resource.getUnfilteredContent().getInputStream();
                             ByteArrayOutputStream out = new ByteArrayOutputStream();
                             byte[] buffer = new byte[4096];
                             int bytesread = 0;
                             while ((bytesread = in.read(buffer)) != -1) {
                                  out.write(buffer, 0, bytesread);
                             String dataToBeConvertedToXML = out.toString();
    catch(Exception e){}
    catch(Exception e){}
    Award points if found usefull.
    I suppose you have used KM sharing reference in ur application
    Regards
    BP

Maybe you are looking for