Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2003
    Posts
    637

    XML/JavaScript Question

    I am very confused about the following instructions. I have no idea what they are telling me to do. Please advise:

    Markup the java code below using XML. Represent the if statement with element if--which contains one or more condition elements and one or more statement elements. Element condition contains the condition (e.g., m == month && d == day) and element statement contains the statements (e.g., resultDay = "DATE: D " + d + " M " +m). Element else represents an else statement in Java and contains one or more statement elements. (Note: Place the Java code inside a CDATA section)

    PHP Code:
    if ( ( == month && == day ) ||
       ( 
    month == -&& == day) ||
       ( 
    == month && day == -1) ||
       ( 
    month > -&& day <= -1) ) {
      
    resultDay "DATE: D " " M " m// a statement
      
    processChildNodes(dateElement.getChildNodes()); // a statement
    }
    else      
    // else statement
      
    return; // a statement 

  2. #2
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    well... it looks like you are working with trees.

    If month is equal to m and day is euqal to d or..... or.... or.....
    resultday will be the above statement , and then it will call a function to get the childnodes..

    else it just returns resultday empty..

    as I think i see (maybe) there is a syntax mistake :
    if ( .......

    without the closing )

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  3. #3
    Join Date
    Jul 2003
    Posts
    637
    Yeah, I'm not worried about what the Java code does though. I'm trying to figure out what this part is instructing me to do:

    "Markup the java code below using XML. Represent the if statement with element if--which contains one or more condition elements and one or more statement elements. Element condition contains the condition (e.g., m == month && d == day) and element statement contains the statements (e.g., resultDay = "DATE: D " + d + " M " +m). Element else represents an else statement in Java and contains one or more statement elements. (Note: Place the Java code inside a CDATA section)"

  4. #4
    Join Date
    Jul 2003
    Posts
    637
    Anyone have any idea what this is telling me to do. I need to do it by tomorrow and I have no clue what it's asking.

  5. #5
    Hello,

    I assume they are asking you to create an XML for the java code with the elements as they have mentioned. It should look something like the following.

    -----------------------------------------
    <?xml version="1.0" encoding="ISO-8859-1" ?>

    <if>
    <condition>m == month && d == day</condition>
    <condition>month == -1 && d == day</condition>
    <condition>m == month && day == -1</condition>
    <condition>month > -1 && day <= -1</condition>
    <statement>resultDay = "DATE" + d + "M" + m</statement>
    <statement>processChildNodes(dateElement.getChildNodes())</statement>
    </if>

    <else>
    <statement>return</statement>
    </else>
    -----------------------------------------

    Hope this helps.

    Cheers,

    Sharon Rose

  6. #6
    Join Date
    Apr 2003
    Location
    Edinburgh, UK
    Posts
    21
    Bear in mind that XML does not allow more than one document root element so strictly Sharon's XML code above isn't valid - but it fits most of the problem well, except that no data is enclosed in <![CDATA[ tags ]]>.

    Logically this problem seems weird (to me at least) - why would the else be floating along separate from the conditions/non-else statements?

    - Salathe
    Sneak in to any website! <--- it's for sale!

  7. #7
    Perhaps you need to add <conditional> ... </conditional> in order for it to be valid xml document. Based on given problem, this is the way we can translate a conditional statement into xml form.

  8. #8
    I missed the root element there, as they have not specified it. Ya, it becomes a valid XML only when the 'if' and the 'else' elements are enlcosed within a single root element. As godong said, you could use <conditional> </conditional> as the root element.
    Thanks and Regards,
    Rose

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •