title: Partially Parsing XML File Without XMLParser in JAVA
body: <p>so I found out it was possible to use the buffered reader/writer to copy an xml file over word for word to a new xml file. However, I was wondering if it would be possible to scrape out only a portion of the document?</p>
  
  <p>For example, looking at this example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;BookCatalogue xmlns="http://www.publishing.org"&gt;
      &lt;w:pStyle w:val="TOAHeading" /&gt;
      &lt;Book&gt;
      &lt;Title&gt;Yogasana Vijnana: the Science of Yoga&lt;/Title&gt;
      &lt;author&gt;Dhirendra Brahmachari&lt;/Author&gt;
      &lt;Date&gt;1966&lt;/Date&gt;
      &lt;ISBN&gt;81-40-34319-4&lt;/ISBN&gt;
      &lt;Publisher&gt;Dhirendra Yoga Publications&lt;/Publisher&gt;
      &lt;Cost currency="INR"&gt;11.50&lt;/Cost&gt;
    &lt;/Book&gt;
    &lt;Book&gt;
      &lt;Title&gt;The First and Last Freedom&lt;/Title&gt;
      &lt;v:imagedata r:id="rId7" o:title="" croptop="10523f" cropbottom="11721f" /&gt; 
      &lt;Author&gt;J. Krishnamurti&lt;/Author&gt;
      &lt;Date&gt;1954&lt;/Date&gt;
      &lt;ISBN&gt;0-06-064831-7&lt;/ISBN&gt;
      &lt;Publisher&gt;Harper &amp;amp; Row&lt;/Publisher&gt;
      &lt;Cost currency="USD"&gt;2.95&lt;/Cost&gt;
    &lt;/Book&gt;
  &lt;w:pStyle w:val="TOAHeading2" /&gt;
  &lt;/BookCatalogue&gt; 
  </code></pre>
  
  <p>Sorry if this is not proper XML Code, I just added the tidbits from the document I was looking at to this sample I found. But basically, if I wanted to look for the an instance of "heading" (in this case, 3rd line -> TOAHeading), then scrape everything from heading down until another instance of heading is found and copy it to another xml file. Is that possible? Furthermore, if I wanted to make that a temporary file I'm storing to, and only keep that file if an instance of "image" (in this case, 14th line) is found, is that possible as well? I'm trying to do this in the simplest way possible, so does anyone have any ideas or experience with this? Thanks in advance.</p>
  
  <pre><code>public class IPDriver 
          {
              public static void main(String[] args) throws IOException
              {
                  BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStreamReader("C:/Documents and Settings/user/workspace/Intern Project/Proposals/Converted Proposals/Extracted Items/ProposalOne/word/document.xml"), "UTF-8"));
                  BufferedWriter writer = new BufferedWriter(new OutputStreamReader(new FileOutputStreamReader("C:/Documents and Settings/user/workspace/Intern Project/Proposals/Converted Proposals/Extracted Items/ProposalOne/word/tempdocument.xml"), "UTF-8"));
  
                  String line = null;
  
                  while ((line = reader.readLine()) != null)
                  {
                      writer.write(line);
                  }
  
                  // Close to unlock.
                  reader.close();
                  // Close to unlock and flush to disk.
                  writer.close();
              }
          }
  </code></pre>
  
  <p><strong>Example From My Actual XML Document</strong></p>
  
  <pre><code>- &lt;w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="address"&gt;
  - &lt;w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="Street"&gt;
  - &lt;w:r w:rsidRPr="00822244"&gt;
    &lt;w:t&gt;6841 Benjamin Franklin Drive&lt;/w:t&gt; 
    &lt;/w:r&gt;
    &lt;/w:smartTag&gt;
    &lt;/w:smartTag&gt;
    &lt;/w:p&gt;
  - &lt;w:p w:rsidR="00B41602" w:rsidRPr="00822244" w:rsidRDefault="00B41602" w:rsidP="007C3A42"&gt;
  - &lt;w:pPr&gt;
    &lt;w:pStyle w:val="Address" /&gt; 
    &lt;/w:pPr&gt;
  - &lt;w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="City"&gt;
  - &lt;w:smartTag w:uri="urn:schemas-microsoft-com:office:smarttags" w:element="place"&gt;
  </code></pre>
  
  <p>Just your basic document.xml file from a .docx</p>