• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

some more mock questions

 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens to the DOM tree if the javax.xml.parsers.DocumentBuilder encounters an error while reading XML data?
Choice 1
It constructs the DOM tree as usual.
Choice 2
The builder assigns a null value to the org.w3c.dom.Document object.
Choice 3
The builder assigns a org.w3c.dom.DocumentFragment to the org.w3c.dom.Document object.
Choice 4
The builder does not assign anything to the org.w3c.dom.Document object.
Choice 5
The builder constructs a partial DOM tree for only the XML data before the error.


java.text.DateFormat df = java.text.DateFormat.getDateInstance();
java.util.Date now = new java.util.Date();
System.out.println("Date Generated: ");
System.out.print(df.format(now));

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns ate="xalan://java.util.Date"
xmlns ateFormat="xalan://java.text.DateFormat"
exclude-result-prefixes="Date DateFormat">

<xsl:template match='/'>
</xsl:template>

</xsl:stylesheet>

Referring to the XSLT and Java code above, what XSLT code do you put inside the template to achieve the equivalent of the Java code?


Choice 1
<xsl:variable name='df' select='DateFormat.getDateInstance()'/>
<xsl:variable name='now' select='new Date()'/>
Date generated:
<xsl:value-of select='$df.format($now)'/>
Choice 2
<xsl:variable name='df' select='DateFormat:getDateInstance()'/>
<xsl:variable name='now' select='Date:new()'/>
Date generated:
<xsl:value-of select='{$df.format($now)}'/>
Choice 3
<xsl:variable name='df' match='DateFormat.getDateInstance()'/>
<xsl:variable name='now' select='new Date()'/>
Date generated:
<xsl:value-of select='DateFormat.format($df, $now)'/>
Choice 4
<xsl:variable name='df' select='DateFormat:getDateInstance()'/>
Date generated:
<xsl:value-of select='df.format(new Date())'/>
Choice 5
<xsl:variable name='df' select='DateFormat:getDateInstance()'/>
<xsl:variable name='now' select='Date:new()'/>
Date generated:
<xsl:value-of select='DateFormat:format($df, $now)'/>



With DOM, why do you use the normalize method?
Choice 1
To balance the DOM tree
Choice 2
To flatten the DOM tree
Choice 3
To combine CDATA sections with adjacent text nodes
Choice 4
To combine adjacent attribute nodes
Choice 5
To combine adjacent text nodes

Thanks
Dhiren
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dhiren Joshi:
What happens to the DOM tree if the javax.xml.parsers.DocumentBuilder encounters an error while reading XML data?

Hint: DocumentBuilder#parse() declares throwing an exception...

Originally posted by Dhiren Joshi:
With DOM, why do you use the normalize method?

Hint: Read the javadocs for org.w3c.dom.Node#normalize()
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With DOM, why do you use the normalize method?
To combine adjacent text nodes - choice 5

What happens to the DOM tree if the javax.xml.parsers.DocumentBuilder encounters an error while reading XML data?
DocumentBuilder throwns SAXException if any parse error occurs. Therefore I think it will not assign anything to Document object - choice 4

Guys, please correct me if I'm wrong. Thanks.
 
Dhiren Joshi
Ranch Hand
Posts: 463
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks every one for the response.
Dhiren
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic