Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: assign values to nodes read from XML using java

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb assign values to nodes read from XML using java

    i am trying to assign unique values to nodes read from XML file.. eg: consider this XML file:

     
    <breakfast_menu>
       <food>
          <name>Belgian Waffles</name>
          <price>$5.95</price>
          <description> ...Strong Belgian waffles...</description>
          <calories>650</calories>
          <chef type="Senior">
               <chef1>Mr. A</chef1>
               <chef2>Mr. B</chef2>
          </chef>
       </food>
       <food>
          <name>Strawberry Waffles</name>
          <price>$7.95</price>
          <description>...Light Strawberry waffles...</description>
          <calories>900</calories>
          <chef type="Senior">
               <chef1>Mr. A</chef1>
               <chef2>Mr. B</chef2>
          </chef>
      </food>
    <breakfast_menu>

    now assigning these nodes "a unique value" has to be done following the LSDX labelling pattern i.e:

    To the document element we first give an “a”.As there is no parent node for the document element, we assign “0” at the front of that “a” . “0a” is the unique code for the document element (breakfast_menu). For the children nodes of “0a”, we continue with the next level of the XML tree which is “1” then the code of its parent node which is “a” and a concatenation “.” . We then add a letter “b” for the first child, letter “c” for the second child, “d” for the third child and so on.Unique codes for children nodes of “0a” shall be “1a.b”, “1a.c”, “1a.d”, etc.Hence foe the above given XML the mapping would look something like this:

    0a breakfast_menu
        1a.b food
           2ab.b name
           2ab.c price
           2ab.d description
           2ab.e calories
           2ab.f chef
              3abf.b chef1
              3abf.c chef2        
        1a.c food
           2ac.b name
           2ac.c price
           2ac.d description
           2ac.e calories
           2ac.f chef 
              3acf.b chef1
              3acf.c chef2

    For more samples about LSDX labelling : 1.) Section 3.1 LSDX Labelling on this link: http://crpit.com/confpapers/CRPITV39Duong.pdf

    2.) Fig 3 on page 1189 on this link: http://books.google.co.in/books?id=F...0nodes&f=false

    right now i am using SAX parser to read xml and get the nodes in their hierarchical order..now the problem is that i have to assign these specific value to their respective nodes using java..can any1 help me out as to how to do this..
    Last edited by bhoots21304; April 13th, 2014 at 01:21 PM.


  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    93
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: assign values to nodes read from XML using java

    SAX parsers don't build in-memory trees. Are you doing that yourself yet? It seems to me you're going to need a tree of objects so you can ask relevant questions about the node, its children, and its parent (directly and how deep from the root) when building your output.

Similar Threads

  1. Merging different nodes of XML files using Java
    By vasouli in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 3rd, 2013, 12:40 PM
  2. Merge 20+ xml files with 7000+nodes into one using java
    By mija in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 3rd, 2013, 02:33 AM
  3. Can java assign hex values?
    By Vaderman2787 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 23rd, 2013, 11:40 PM
  4. Assign Default values to the JTextfield in java swing
    By sjohnfernandas in forum AWT / Java Swing
    Replies: 1
    Last Post: December 17th, 2011, 06:59 AM
  5. how to assign values to (args) from Jcreator
    By amr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 14th, 2010, 03:41 PM

Tags for this Thread