Read specified content of a xml file

How to get specified part of a xml file
This is the content of the xml file, I just want the content in the <body>...</body> without the <p></p> tag. How can I do that?
<?xml version="1.0" encoding="UTF-8"?>
<TEI.2>
<teiHeader>
<fileDesc>
<titleStmt>
<title>Pastikan kita terus bebas -- PM: Kekalkan perpaduan, jangan terpengaruh dakyah asing di alaf baru
</title>
<author>MOHD. NOR AB. SAMAD
</author>
</titleStmt>
<publicationStmt>
<publisher/>
</publicationStmt>
<sourceDesc>
<!-- ... -->
</sourceDesc>
</fileDesc>
<profileDesc>
<textClass>
<catRef target="Muka_Hadapan"/>
</textClass>
</profileDesc>
</teiHeader>
<text>
<front>
<!--
                  front matter ...
             -->
</front>
<body>
<p>- Datuk Seri Dr. Mahathir Mohamad mengajak rakyat supaya mengekalkan perpaduan dan belajar daripada sejarah negara serta tidak terpedaya dengan dakyah asing bagi memastikan Malaysia terus bebas, merdeka dan maju pada alaf akan datang.</p>
<p>Sambil mengingatkan mereka usaha menjajah semula negara masih diteruskan oleh bekas penjajah, Perdana Menteri berkata, kemerdekaan negara tidak akan kekal selama-lamanya jika rakyat mengabaikan perkara tersebut.</p>
<p/>
<p/>
<p/>
</body>
<back>
<!--
                  back matter ...
             -->
</back>
</text>
</TEI.2>

I can get the first <p> tag only. How to get others <p> tag content?
How I know how many <p> node that it have if i use while loop?
     public static String ParserWord(String pathname, String tag) {
            Text result = null;
            try{
              DOMParser parser = new DOMParser();
                parser.parse(pathname);
                Document doc = parser.getDocument();
                NodeList doubles = doc.getElementsByTagName(tag);
                Node datum = doubles.item(0);
                result = (Text) datum.getFirstChild();
             catch (Exception e) {
              System.err.println(e + "cannot parse");
         return result.getNodeValue();
       }

Similar Messages

  • Help on how to read the content of an XML file from the payload

    I have a receiver channel / mail adapter, that sends e-mails with a XML attachment.
    I’m trying to write a Bean, that should make it possible to rename the attached XML file dynamically.
    In the Bean I want to read the content of the attached XML file, it could be the “order number”.
    The filename should then be “Order number”.XML.
    <u><i>Can anyone help me with how to read the content of the XML file from the payload.</i></u>
    <i><b>Frank</b></i>

    hi,
    check this: http://jakarta.apache.org/poi/

  • FTP to Read content of Text/xml file

    Hi,
    I need a help for reading content of text/xml file through FTP. Below I just am explaining the scenario.
    Our application server is in UNIX. Now we have to run a report program to access in to a FTP server which is in windows platform. Using FTP_CONNECT, FTP_COMMAND, FTP_DISCONNECT we are able to connect to FTP server and also able to copy files from FTP server to SAP application server. After copied in application server, we are able to read the content of the txt file in to internal table in ABAP program using OPEN DATASET. But our requirement is that we want to read the text or xml file content into internal table while accessing into FTP server from SAP application instead of after copying the file into application server.
    So please help me to solve my problem.
    -Pk

    Thank you Bala,
    But can you help me what should I pass against FNAME and CHARACTER_MODE Import parameter? Should I pass the full path of the file with name or only I have to pass file name ? For example if my text file name in FTP Server is test.txt and the IP of the ftp server is 10.10.2.3 then should I pass the value against FNAME as '
    10.10.2.3\xyz\text.txt' ? Here xyz is the name of the directory in C drive where test.txt is exist.
    Please help me.
    -pk

  • How to read the content of a text file (by character)?

    Guys,
    Good day!
    I'm back just need again your help. Is there anyone knows how to read the content of a text file not by line but by character.
    Please help me. Thank you so much in advance.
    Jojo

    http://java.sun.com/javase/6/docs/api/index.html
    package java.io
    InputStream.read(): int
    Reads the next byte of data from the input stream.
    Implementation:
    InputStreamReader
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

  • Error in reading the contents of a zip file

    EHello Experts,
    I want to read the contents of a zip file.I have written the following program which reads the contents of a file named "index.xml" which resides in ReadZip.zip.My problem is , it is reading only the first line of that file & after that it is giving this error.
    java.io.IOException: Stream closed
    at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:43)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:67)
    at components.ReadZipFile2.main(ReadZipFile2.java:26)
    public class ReadZipFile2 {
        public static void main(String args[]) {
            try {
                FileInputStream fis = new FileInputStream("C:\\ReadZip.zip");
                ZipInputStream zis = new ZipInputStream(fis);
                ZipEntry ze;
                while ((ze = zis.getNextEntry()) != null) {
                    System.out.println(ze.getName());
                    if (ze.getName().equals("ReadZip/index.xml")) {
                        long size = ze.getSize();
                        if (size > 0) {
                            System.out.println("Length is " + size);
                            BufferedReader br = new BufferedReader(
                                    new InputStreamReader(zis));
                            String line;
                            while ((line = br.readLine()) != null) {
                                System.out.println(line);
                            br.close();
            } catch (IOException e) {
                e.printStackTrace();
    }It seems that zis is getting close after reading the first entry of file.I am unable to guess the reason for this.Please help.Thanx in advance.

    [redacted confused advice]
    [_Compressing and Decompressing Data using Java - with many code samples_|http://java.sun.com/developer/technicalArticles/Programming/compression/|Yes Virginia, there really are code samples]

  • Reading rule sets from an XML file

    Hi all,
    How can I read rule sets from an XML file? I have been given some rules in XML
    format and using those I have to query some content. I am using WLP4.0
    Also how can I code rules in java?
    Thanks in advance.

    You can have the following classes:
    Players class deriving from Vector (or containing a vector), and then
    Player class with attribute 'name'.
    class Players
               Vector myVector = new Vector();
                void addPlayer(Player p)
                      myVector.add(p);
                Player getPlayer(int index)
                      myVector.get(index);
    class Player
             private String myName = null;
             Player(String name)
                    this.myName = name;
             String getName()
                    return myName;
    }Then while handling the SAX events you can do the following:
    class MySAXHandler implements ContentHandler (or whatever the itnerface is)
                 public void startElement(String name,....)
                          Players p = null;
                          if(name.equals("Players"))
                                 p = new Players();
                         else if (name.equals("Name"))
                                p.add(new Player(value));
    }HTH,
    Kalyan.

  • Specifying Schema Location in XML file and not in the Java code

    I have a repository of schema xsd files. When I receive my xml file, I need to validate it against the specified schema. The xml file would declare the schema location, using the following syntax:
    <CERD:CERD xsi:schemaLocation = "..\CERD.xsd" xmlns:CERD = "CERD.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
    Is it really necessary to define the schema location again in the JAVA code? Why set the schemaLocation in the xml file at all then?
    Does anybody have any examples where the schema location is not set in the JAVA code? I am using Java 1.6, and at this point in time I only need to validate. Any help would be appreciated.

    Thank you very much for your quick reply. I have made some progress but I am still stumped.
    In my code I am doing this:
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = factory.newSchema();
    Validator validator = schema.newValidator();
    validator.validate(XML_SOURCE);
    I find this works if my schema does not have a target namespace. I have downloaded the following simple example from the internet that uses a target namespace and it fails:
    library1.xsd:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.org/prod"
    xmlns:prod="http://example.org/prod">
    <xsd:element name="product" type="prod:ProductType"/>
    <xsd:complexType name="ProductType">
    <xsd:sequence>
    <xsd:element name="number" type="xsd:integer"/>
    <xsd:element name="size" type="prod:SizeType"/>
    </xsd:sequence>
    <xsd:attribute name="effDate" type="xsd:date"/>
    </xsd:complexType>
    <xsd:simpleType name="SizeType">
    <xsd:restriction base="xsd:integer">
    <xsd:minInclusive value="2"/>
    <xsd:maxInclusive value="18"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>
    <prod:product xmlns:prod="http://example.org/prod"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="library1.xsd"
    effDate="2001-04-02">
    <number>557</number>
    <size>10</size>
    </prod:product>
    I get the following SAXParseException when I validate:
    [line 4, col 36|
    cvc-elt.1: Cannot find the declaration of element 'prod:product'.
    Am I doing something wrong with the namespace declaration?
    Edited by: alfredamorrissey on Oct 31, 2007 6:34 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can a search engine read the contents of a Library file embedded in a page?

    Can a search engine read the contents of a Library file
    embedded in a page? Or would SSI be the way to go. I'm creating a
    large library of text-based information and links, and I want to
    have much of it modular so I can add a link and all the many pages
    on my site updates to reflect the change. A big concern is that
    when a search engine visits my site, can it read the content
    embedded in the library item, or is SSI a better method to help the
    search engine read my content?
    Thanks

    Yes, search engines can read Dreamweaver library items. The
    library only exists on your own hard drive. Once you add the
    library item to your pages it's in there as regular HTML.
    If you have more than 20 pages on your site, they say SSI is
    better, because when you update you only update the SSI. If you
    stick with library items each page has to be uploaded every time
    the library is updated.

  • How to read the content of this excel file in LV

    Hi could you please let me know how can I read the content of this excel file using the Read From Speardsheet function. It contains text and numbers
    Thanks
    The excel file is attached
    Attachments:
    Datalogging.zip ‏307 KB

    Check attached VI.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.
    Attachments:
    ReadFromExcel.vi ‏27 KB

  • To Read the contents of the properties file which is located in webserver

    Hi,
    I have one requirement where I have to read the contents of a property file which is located in some path in server. Say for example, when you click on link abcd then contents of abcd.properties file should be displayed in one text view in webdynpro . I am trying to implement this in webdynpro for java. The main thing is like I am not able to retrieve the server path of the file and hence not getting the file contents. I tried using methods like  getApplicationPath() or getRealPath() but its not working. So can you guys please help me on to how to read the server file contents.
    Thanks and regards,
    Sai

    Hi Romano,
    Thanks a lot for your reply. However, I forgot to mention one thing in my question. Its like the path will be different everytime. Say, we have systems like development, acceptance, production. So when the user clicks on the link abcd, it should take the path of development system and similarly when the user clicks on the link in acceptance or production, the path will be different. say for example, in development the path will be
    usr/cluster/dev/abcd.properties but it acceptance it will be usr/cluster/acc/abcd.properties. So just want to know whether this will work? Anyway, I will give this a try.
    Thanks once again,
    Sai

  • How to read the content of ms-word file use pure java???

    how to read the content of ms-word file use pure java???

    hi,
    check this: http://jakarta.apache.org/poi/

  • How to read configuration data from an xml file (not web.xml)?

    Hi,
    I want to separate the application specific configuration parameters in a separate xml file and read them as and when they are needed? I know that I can use the wb.xml but I want to separate them in a different xml file because I don't want the web.xml file to be played around later after deployment. If any change is needed then it should be done in the application-config.xml.
    How can I read the parameters from this xml file in my jsp code and also what should be the location of this file if I have
    ../webapps/Root/application
    directoty structure ?
    Any help is greatly appreciated.

    can you give an example of a property file and also
    it is loaded in the jsp ?Hmm... loading properties in a JSP is not a very good idea. You should do it in a separate class, rather than mixing the logic with the display logic.
    Properties properties = new Properties();
    properties.load(UtilClass.class.getResourceAsStream("config.properties"));
    // Add a try - catch block around the load
    // for IOException...

  • Reading an XML file and write the contents to another xml file in java

    Hi,
    I am new to xml parsing.My requirement is that I am getting a message (xml) using ibm MQ in the ByteArrayInputStream format.I have to read this xml message and write to another file.
    I am creating a POC for this.
    First I used simple reading and writing concept but the output is "java.io.FileInputStream@3e25a5 "
    Sample xml file
    - <Client>
    <ClientId>1234</ClientId>
    <ClientName>STechnology</ClientName>
    <DTU_ID>567</DTU_ID>
    <ClientStatus>ACTIVE</ClientStatus>
    - <LEAccount>
    <ClientLE>678989</ClientLE>
    <LEId>56743</LEId>
    - <Account>
    <AccountNumber>9876543678</AccountNumber>
    </Account>
    </LEAccount>
    - <Service>
    <Cindicator>Y2Y</Cindicator>
    <PrefCode>980</PrefCode>
    <BSCode>876</BSCode>
    <MandatoryContent>MSP</MandatoryContent>
    </Service>
    </Client>
    code:
    import java.io.ByteArrayInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class ByteArrayInputStreamToXml {
         public static void main(String srg[]) throws IOException{
              InputStream inputStream= new FileInputStream("C:\\soft\\test2\\sample1.xml");
              byte currentXMLBytes[] = inputStream.toString().getBytes();
              ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);
              OutputStream out = new FileOutputStream("C:\\soft\\test\\data.xml");
              int read=0;
              byte[] bytes = new byte[1024];
              while((read = byteArrayInputStream.read(bytes))!= -1){
              out.write(bytes, 0, read);
              out.write( '\n' );
              inputStream.close();
              out.flush();
              out.close();
              System.out.println("New file created!");
    Please suggest me how can I use DOM/SAX parser ,I can see several code on net for reading xml file using SAX/DOM parser but writing an xml file after reading it using ByteArrayInputStream I am not getting .A help through some example Link will also be helpful for me.
    Thanks
    Sumit
    Edited by: user8687839 on Apr 30, 2012 2:37 AM
    Edited by: user8687839 on Apr 30, 2012 2:43 AM

    Thanks I got the result.
    package com.sumit.collections;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class ByteArrayInputStreamToXml {
         public static void main(String srg[]) throws IOException{
              InputStream inputStream= new FileInputStream("C:\\soft\\test2\\sample1.xml");
              ByteArrayOutputStream buffer = new ByteArrayOutputStream();
              int nRead; byte[] data = new byte[1024];
              while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
              buffer.write(data, 0, nRead); } buffer.flush();
              byte currentXMLBytes[]= buffer.toByteArray();
              /* byte currentXMLBytes[] = inputStream.toString().getBytes();*/
              ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);
              OutputStream out = new FileOutputStream("C:\\soft\\test\\data.xml");
              int read=0;
              byte[] bytes = new byte[1024];
              while((read = byteArrayInputStream.read(bytes))!= -1){
              out.write(bytes, 0, read);
              out.write( '\n' );
              inputStream.close();
              out.flush();
              out.close();
              System.out.println("New file created!");
    }

  • Changing content type of xml file to pdf

    Hello,
    I have an xml file (extension is *.xdp) which can locally be opened with Adobe Reader and displays as a regular pdf file. Adobe has a technology that allows xml to be merged with a pdf shell, and thus populating the pdf file with the values retrieved from the xml file.
    My issue is that I want this to be done on an application server level (jboss in particular). In a servlet, I stream the xml file for the contents to be printed out within a browser (IE). I specify the content type to be application/pdf, however, the data is not being displayed within Adobe Reader, but rather as a regular xml file.
    Any help is greatly appreciated. Here is the code below:
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "max-age=30");
    response.setContentType("application/pdf");
    ServletOutputStream out = response.getOutputStream();
    byte[] fileBytes = readFile();
    out.write(fileBytes);

    Yes, the xml does contain a reference to the shell pdf. This works fine if I do so manually (open the xml file using Adobe Reader). However, through a browser, it seems that the forced content type is completely ignored:
    <?xml version="1.0"?>
    <?xfa generator="XFA2_0" APIVersion="1.4.4127.0"?>
    <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
    <xfa:datasets xmlns="" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
    <xfa:data>
    <DocRoot>
    <Cldemographics<Cldatecreated>7/21/05</Cldatecreated...
    </DocRoot>
    </xfa:data>
    </xfa:datasets>
    <pdf href="/opt/jboss-tomcat-server-build-4.0.0-2/.../pdfShell/Shell.pdf"
    xmlns="http://ns.adobe.com/xdp/pdf/"/>
    </xdp:xdp>

  • Specifying servlet classpath in xml file

              Hi there...
              Am trying to achieve dynamic class reloading for my web application, and have
              specified the servlet classpath in my web.xml file. However my server still loads
              classes that exist on the classpath first, and ignores any 'later' versions I
              have placed in the servlet classpath.
              My question would be do I really have to split up my jar files and place the individual
              classes on the servlet classpath, or can I specify two or more parameters under
              the "context-params" in the web.xml.
              Ideally I would like to be able to keep my jars whole, and upload classes to override
              the contents of the jar, and at the moment I can't see a way to achieve this !!
              Many thanks for any help anyone might be able to give !!
              George
              

    I'm no expert with WAR files and 5.1 but....
              Have you tried putting your jar files and any non-weblogic specific jars in
              to your WEB-INF/lib directory?
              Then you dont have to specify them in the classpath when starting weblogic.
              Following this - i think you should be a step closer to dynamic class
              reloading.
              "George Cover" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Thanks for the prompt response...unfortunately we are still at version 5,
              with
              > a service pack level of 10 (which has just gone live). However we do have
              our
              > environments set up as much as possible in a J2EE fashion.
              >
              > We still specify a classpath, where the jars are kept, however we also
              have WEB-INF
              > directories, where compiled classes (jsp, and shock horror, jhtml) are
              kept !!
              >
              > I think that placing classes in here, puts me in a similar situation as
              placing
              > them on the servlet classpath, the jars still override them !!
              >
              > Also the halfway house our server environments are in, plus the fact they
              are
              > all constantly changing, makes it difficult to predict behaviour, or even
              come
              > close to understanding what might happen if I change configurations here
              and there
              > !!
              >
              > Many thanks
              > George
              >
              > "Matt Krevs" <[email protected]> wrote:
              > >What version of weblogic are you using?
              > >
              > >If you are using 6.0 or greater - my understanding is that you dont
              specify
              > >your classes in the classpath when starting weblogic. Your classes and
              > >jars
              > >should be in web-inf/classes and web-inf/lib and should be loaded from
              > >there.
              > >
              > >"George Cover" <[email protected]> wrote in message
              > >news:[email protected]...
              > >>
              > >> Hi there...
              > >>
              > >> Am trying to achieve dynamic class reloading for my web application,
              > >and
              > >have
              > >> specified the servlet classpath in my web.xml file. However my server
              > >still loads
              > >> classes that exist on the classpath first, and ignores any 'later'
              > >versions I
              > >> have placed in the servlet classpath.
              > >>
              > >> My question would be do I really have to split up my jar files and
              > >place
              > >the individual
              > >> classes on the servlet classpath, or can I specify two or more
              parameters
              > >under
              > >> the "context-params" in the web.xml.
              > >>
              > >> Ideally I would like to be able to keep my jars whole, and upload
              classes
              > >to override
              > >> the contents of the jar, and at the moment I can't see a way to achieve
              > >this !!
              > >>
              > >> Many thanks for any help anyone might be able to give !!
              > >> George
              > >
              > >
              >
              

Maybe you are looking for

  • IPod Nano error.. Help :c

    alright everytime i try to add a song this box comes up "The iPod cannot be updated. An unknown error occurred(-69). is there any way aside from restoring to solve my problem? muchos gracias!

  • Apple update not seeing Bootcamp 3.1 (WIN 7, 64 BIT)

    ok i have this problem for a while now. I look in my "programs and features" the the control panel and it says im updated to 3.1 but when i run apple update it tells me i need to download and install 3.1. i have uninstalled and reinstalled the 3.0 fr

  • Moving OTC processes from SAP R/3 into SAP CRM 5.0

    Hi all, A SAP CRM client that I am currently working on have decided to extend the project scope and now want to move all their existing OTC processes from R/3 to CRM 5.0. Their system is heavily bespoked with a high level of user exits, as during th

  • Can you print to PDF with Adobe Digital Editions?

    I have Adobe Acrobat Professional 8.0 on a PC I use at school. I am able to print documents to Adobe PDF and create them into a PDF by choosing Adobe PDF instead of a printer. I have purchased an eBook that opens in Adobe Digital Editions. The book a

  • Help with Recovery and Time machine

    So a friend of mine sent me her laptop to change hard drives.  She also sent her Time machine external HDD.  I used her drive as a recovery disc using the Lion recovery tool.  I didnt see or didnt read any where that stated the drive would be unusabl