View Single Post
  #1 (permalink)  
Old 05-05-2008, 02:30 PM
Java_Chick Java_Chick is offline
Newbie
 
Join Date: May 2008
Posts: 14
Rep Power: 0
Java_Chick is on a distinguished road
Question XML parser in Java

I have to make XML parser, for the xml file I have.I wrote

the code for reading it, but I need just an example for a

part of code.

This is what I made so far:
Code:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.regex.*;

public class Main {

  public static void main(String[] args) {

    File file = new File("C:/EES.xml");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    try {
      fis = new FileInputStream(file);

     
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      while (dis.available() != 0) {


        System.out.println(dis.readLine());
      }

      fis.close();
      bis.close();
      dis.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
This is XML file:
Code:
<?xml version="1.0" encoding="utf-8"?>

<Circuit>

<Elements>

<E1>
<value>20</value>
</E1>

<E2>
<value>10</value>
</E2>

<R1>
<value>120</value>
</R1>

<R2>
<value>100</value>
</R2>

</Elements> 
<!--In this part I'm just telling which elements exist 

(elements of an electronic circuit, doesn't matter now), and 

their values.I should assing variables for each value, so 

latter on I could solve math equations system.Also, every 

element should in the start get two points:A and B-->


<Linking>

<E12>
<A>R1A</A>
<B>R2A</B>
</E12>

<E23>
<A>R1A</A>
<B>R2B</B>
</E23>

<R12>
<A>E1A</A>
<B>R2A,E1B</B>    
<!--when their is a ",", it means that the element is linked 

with two other elements, it's in "parallel" whith them-->
</R12>

<R23>
<A>R1B,E1B</A>
<B>E2B</B>
</R23>

</Linking> 
<!--Now every A and B spot has it's pair ( or more pairs ) - 

the other part of some element.This is the job of a parser, 

latter comes math-->

</Circuit>
For me it's a bit complicated, but If someone could just

write me a part of the code, example for E1 tag in Elements

tag, I could write the rest.
Reply With Quote

Sponsored Links