This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Product and Other Certifications and the fly likes Fresher ! need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Fresher ! need help" Watch "Fresher ! need help" New topic
Author

Fresher ! need help

patrick gee
Greenhorn

Joined: Sep 30, 2002
Posts: 9
Hi there,
Iam preparing for IBM-XML cert.
I like to work out some examples. May be it's a silly question :-(
could u pls reply me what r all the parsers & tools i need,to run a XML program in a PC.
I need a java based Parser!Plz help me with the links.
thanks for ur time


The greatest risk is not taking one!
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Hi there,
The following info is a little exhaustive. Please go through it completely,
I tried to compile a list of resources for preparing for the IBM XML test141. Please come back with any comments/suggestions/clarifications.
DISCLAIMER � I�ve not yet taken the test and the following list is what I�m following
EXAM INFO - http://www1.ibm.com/certify/certs/adxm_apd.shtml
Exam pattern � IBM has changed the pass percentage from 65% to 58% and the no. of questions were lowered from 59 to 55. Hence we need to get a minimum of 32 correct answers in order to clear the exam. All of them are going to be multiple choice types. Seems that they also mention the number of correct answers for the non-radiobutton questions.
Mock Exams � The best mock exam I could find out till date is that of the IBM website�s given here ----- http://certify.torolab.ibm.com/icetest.jsp You just need to create some login and everything is free.
AND
JavaRanch mock exams under the xml certification forum.
Books (hardcopies) - Professional XML2. No other hard copies are required in my opinion. Exhaustive list of reading material available on the web follows J
SoftCopies
===========
�Lots of sample chapters available topic-wise at http://www.perfectxml.com/FreeLibrary.asp
�The following are links for preparing for XML-Databases part of the exam �
http://www-106.ibm.com/developerworks/library/x-struct/?dwzone=xml
http://www.rpbourret.com/xml/SchemaMap.htm
http://www.extensibility.com/tibco/resources/modeling.htm
http://www.rpbourret.com/xml/XMLAndDatabases.htm
http://www.xml.com/pub/a/2001/05/09/dtdtodbs.html?page=1

MAIN TOPICS WE NEED TO CONCENTRATE UPON
Remember �.. You need to verify the concepts with the help of tools (provided here) in order to understand them thoroughly.
1.General XML and DTDs � XML Bible has very good introduction to these concepts including in-depth coverage of entities and all that good stuff of DTDs.
Testing tool
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/Downloads/samples/Internet/xml/xml_validator/Default.asp
The above link has microsoft�s xml validator. I use this for validation of my xml instance documents against the DTDs. I think this can also be used to validate against schemas, but I never tried it.
2.Schemas � You need to get Roger Costello�s tutorial from the following location. It is simply the best available on the web. It has 3 ppt files on schemas.
http://www.xfront.com/xml-schema.html
Testing tool
The xml schema validator XSV given here is provided on Roger Costello�s website given here � ftp://ftp.cogsci.ed.ac.uk/pub/XSV/XSV12.EXE
This can be used to validate the xml documents against the schemas we write.
3.XSLT � One of the best tutorials available on the web for xslt is given below. The best part is that it explains things with examples.
http://zvon.org/xxl/XSLTutorial/Output/contents.html
Testing tool
You need to have Xalan�s Java based XSLT processor and the following details you how to install that stuff on your m/cs (you need to have Java SDK1.2 or later).
This takes care of 3 birds in one shot XSLT, DOM and SAX testing tools �
http://xml.apache.org/xalan-j/
You will be applying the stylesheets to the xml files from the command line.
The following are the sequence of steps i followed to get the stuff working on my m/c -
1) download xalan-j_2_4_0-bin.zip from the above site
2) extract the zip file in any of the directories
3) You then need to go to the xalan/bin directory and extract the contents of some of the jar files here as "jar -xvf xalan.jar", then the same thing for xercesImpl.jar and xml-apis.jar. This process will basically extract all the class files which will be used by the our xslt processor.
4) The most important thing then is to update the CLASSPATH variable on our m/c with the absolute path of our xalan/bin directory.
5) To ensure that everything is properly set up on ur m/c, you need to run the following command from the command line -
java org.apache.xalan.xslt.Process
and it should give you a list of options as shown below -
=================================================
-IN inputXMLURL
-XSL XSLTransformationURL
-OUT outputFileName
-V (Version info)
-QC (Quiet Pattern Conflicts Warnings)
-TT (Trace the templates as they are being called)
-TG (Trace each result tree generation event)
-TS (Trace each selection event)
-TTC (Trace the template children as they are being processed)
-EDUMP [optional]FileName (Do stackdump on error)
-XML (Use XML formatter and add XML header)
-TEXT (Use simple Text formatter)
-HTML (Use HTML formatter)
-PARAM name value (Set a stylesheet parameter)
-DIAG (Print number of milliseconds transform operation took)
-FLAVOR flavorName (Transform with SAX for s2s or DOM for d2d)
-URIRESOLVER fullClassName (Use a custom URIResolver)
-ENTITYRESOLVER fullClassName (Use a custom EntityResolver)
-CONTENTHANDLER fullClassName (Use a custom ContentHandler)
-INCREMENTAL (Request incremental transform by setting
http://xml.apache.org/xalan/features/incremental to true)
-NOOPTIMIZE (Request no optizimation of stylesheet processing
by setting http://xml.apache.org/xalan/features/optimize to
false)
-RL recursionLimit (Set numeric limit on depht of stylesheet
recursion)
-L (Turn on source_location attribute)
================================================
This make sure that you are all set to go. If you didnot set the classpath stuff properly, you will get the no class defintion found error. Also one common mistake people do is forget to include the current directory �.� In their classpath.
6) Next thing is that you need to write a sample test.xml file (say) and write some xsl file for that (test.xsl) and run the command as follows -
java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -out test.txt
You can find all these details at http://xml.apache.org/xalan-j/
Xpath and XSLT are inter-twined. We have a good tutorial for Xpath at the following location - http://www.oreilly.com/catalog/xmlnut/chapter/ch09.html
4.DOM - Java�s Xalan Xslt processor has all the DOM API implementation classes for java. Read the above procedure for installing the xalan processor carefully and this will set up the required things for DOM and SAX in java.
The best way for understanding the DOM API in my opinion is try to practice one of its implementations. I�m following Java�s from the following website �
http://java.sun.com/j2se/1.4.1/docs/guide/plugin/dom/org/w3c/dom/package-summary.html
I�m giving you a small java program written using this DOM API to give you a head start to start working with this. Please go through the code thoroughly to understand the process. In a nutshell, I�m trying to walk through the DOM tree build by parsing the xml file �aa.xml�. You need to copy the following xml code in a file named aa.xml and the java code in a file named order.java.
XML File to be parsed �
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE orders [
<!ELEMENT orders (order*)>
<!ELEMENT order (customerid, status, item*)>
<!ELEMENT item ANY>
<!ELEMENT status (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT qty (#PCDATA)>
<!ATTLIST customerid limit CDATA #REQUIRED>
<!ATTLIST orders Notation ENTITY #IMPLIED>
<!ATTLIST item instock CDATA #REQUIRED
itemid CDATA #REQUIRED>
<!ENTITY jaya "WB78">
<!ENTITY jayaTwo "&elementEntity;">
<!ELEMENT jaya (#PCDATA)>
<!ENTITY elementEntity "<jaya>jayadev</jaya>">
<!NOTATION jaya SYSTEM "jaya.exe">
<!ENTITY giffile SYSTEM "demo.gif" NDATA jaya>
]>
<?PI-1 this is first processing instruction?>
<orders Notation="giffile">
<order>
<?PI-2 this is second processing instruction?>
<customerid limit="1000">12341</customerid>
<status>pending</status>
<item instock="Y" itemid="SA15">
<![CDATA[hi there]]>
<name>Silver Show Saddle, 16 inch</name>
<price>825.00</price>
<qty>1</qty>
</item>
<item instock="N" itemid="C49">
<![CDATA[hi there]]>
<name>Premium Cinch</name>
<price>49.00</price>
<qty>1</qty>
</item>
</order>
<order>
<?PI-3 this is third processing instruction?>
<customerid limit="150">251222</customerid>
<status>pending</status>
<item instock="Y" itemid="&jaya;">
&jayaTwo;
<!-- &giffile; -->
<![CDATA[hi there]]>
<name>Winter Blanket (78 inch) &jaya;</name>
<price>20</price>
<qty> 10</qty>
</item>
</order>
</orders>
DOM Java CODE �
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.io.File;
import org.w3c.dom.*;
public class order{
public static int depth;
public static void changeOrder(Node root, String elementName,
String elementValue)
{
Node n;
Node firstChild;
try{
Document doc = root.getOwnerDocument();
NodeList nList = doc.getElementsByTagName(elementName);
for(int i=0; i<nList.getLength(); i++)
{
n = nList.item(i);
// text node will be the first child
firstChild = n.getFirstChild();
firstChild.setNodeValue(elementValue);
}
}
catch(DOMException de)
{
System.out.println("DOMException::"+de.toString());
}
catch(Exception e)
{
System.out.println("Exception::"+e.toString());
}
}
public static void showAttributes(Node element)
{
NamedNodeMap nnMap = element.getAttributes();
Node indexedNode;
for(int i=0; i<nnMap.getLength(); i++)
{
for(int j=0; j<depth; j++) System.out.print(" ");
indexedNode = nnMap.item(i);
System.out.println("ATTR::"+indexedNode.getNodeName()+"="+
indexedNode.getNodeValue()+"("+getNodeType(indexedNode)+")");
}
}
public static String getNodeType(Node node)
{
short type;
type = node.getNodeType();
String retNode = "UNKNOWN";
if(type == node.ELEMENT_NODE) retNode="ELEMENT_NODE";
if(type == node.ATTRIBUTE_NODE) retNode="ATTRIBUTE_NODE";
if(type == node.COMMENT_NODE) retNode="COMMENT_NODE";
if(type == node.PROCESSING_INSTRUCTION_NODE) retNode="PROCESSING_INSTRUCTION_NODE";
if(type == node.ENTITY_REFERENCE_NODE) retNode="ENTITY_REFERENCE_NODE";
if(type == node.ENTITY_NODE) retNode="ENTITY_NODE";
if(type == node.NOTATION_NODE) retNode="NOTATION_NODE";

if(type == node.TEXT_NODE) retNode="TEXT_NODE";
if(type == node.DOCUMENT_NODE) retNode="DOCUMENT_NODE";
if(type == node.DOCUMENT_TYPE_NODE) retNode="DOCUMENT_TYPE_NODE";

if(type == node.CDATA_SECTION_NODE) retNode="CDATA_SECTION_NODE";
if(type == node.DOCUMENT_FRAGMENT_NODE) retNode="DOCUMENT_FRAGMENT_NODE";
return retNode;
}
public static void recurseNodes(Node node)
{

for(int i=0;i<depth; i++) System.out.print(" ");
// print the node information
if(node.getNodeType() == node.TEXT_NODE)
{
if(node.getNodeValue().trim().length() > 0){
System.out.println(node.getNodeName()+"="+
node.getNodeValue()+"("+getNodeType(node)+")");
}
else
{
System.out.println(node.getNodeName()+"="+"("+getNodeType(node)+")");
}
}
else
{
System.out.println(node.getNodeName()+"="+
node.getNodeValue()+"("+getNodeType(node)+")");
}
// print the node attributes
if(node.getNodeType() == node.ELEMENT_NODE)
showAttributes(node);
// recurse thru the children
Node firstChild = node.getFirstChild();
while(firstChild!=null)
{
depth ++;
recurseNodes(firstChild);
firstChild = firstChild.getNextSibling();
}
depth--;
}
public static void main (String args[]) {
File docFile = new File("cc.xml");
Document doc = null;
NamedNodeMap nnMap = null;
int i;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setExpandEntityReferences(false);
dbf.setIgnoringElementContentWhitespace(true);
DocumentBuilder docb = dbf.newDocumentBuilder();
doc = docb.parse(docFile);
Element root = doc.getDocumentElement();
System.out.println("RootElement::"+root.getNodeName());
NodeList nList = root.getChildNodes();
System.out.println("No. of children for root node "+
nList.getLength());
depth=0;
/*
//recurseNodes(root);
// Details of the DTD
System.out.println("-------------DTD DETAILS----------");
DocumentType docType = doc.getDoctype();
System.out.println("DTD Name ::"+docType.getName());
nnMap = docType.getEntities();
System.out.println("No. of general Entities ::"+nnMap.getLength());
// Entity information
for(i=0;i<nnMap.getLength();i++)
{
System.out.println("Index ::"+i+""+nnMap.item(i).getNodeName()+"="+
nnMap.item(i).getNodeValue());
}
nnMap = docType.getNotations();
System.out.println("No. of Notations ::"+nnMap.getLength());
// Entity information
for(i=0;i<nnMap.getLength();i++)
{
System.out.println("Index ::"+i+""+nnMap.item(i).getNodeName()+"="+
nnMap.item(i).getNodeValue());
System.out.println("Notation SYSTEM ::"+((Notation)nnMap.item(i)).getSystemId());
}
// changing the element content
// changeOrder(root, "status", "processed");
// recurseNodes(root);
// adding new nodes
Element newElement = doc.createElement("newElement");
// TBD:: Try to set a node value to an element node
// TBD:: Try to create an element with an invalid name
Node textNode = doc.createTextNode("newTextNode");
textNode.setNodeValue("NEW TEXT");
newElement.appendChild(textNode);
root.appendChild(newElement);
root.insertBefore(newElement, root.getFirstChild());
root.removeAttribute("Notation");
//root.normalize();
//recurseNodes(root);
System.out.println(root.toString());
*/
/*
Node n = doc.getElementsByTagName("order").item(1);
NodeList l = ((Element)n).getElementsByTagName("qty");
Node nn = l.item(0);
Text t = doc.createTextNode("Move along, nothing to see here.");
nn.appendChild(t) ;
*/
recurseNodes(root);
/*
root.normalize();
recurseNodes(n);
*/
}
catch (DOMException de)
{
System.out.println("DOM Exception ::"+de.toString());
}
catch (Exception e)
{
System.out.println("EXCEPTION::"+e.toString());
System.out.println(e.getClass());
}
}
}
5.SAX - SAX preparation should be very similar to DOM. The following website gives you Java�s implemtation of the API. All the java classes required to run examples are already available as a part of installing the xalan�s xslt processor on your m/c.
http://java.sun.com/j2se/1.4.1/docs/api/org/xml/sax/package-summary.html

Try to be in take as many DIFFERENT mock exams as possible. All the best for your exam and please wish me good luck.
Regards,
Jayadev.
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1449
patrickm,
Please review the JavaRanch Naming Guidelines and change your login name.
Thanks,


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
patrick gee
Greenhorn

Joined: Sep 30, 2002
Posts: 9
Thanks Jaydev,
Ur reply is a wonderful resource.
I will try to do that if i have any problem i will get back to u.
thanks man.
Anitha Lingam
Ranch Hand

Joined: Apr 21, 2002
Posts: 38
Jayadev,
Can you please tell how to use the schema validator XSV to validate the xml documents against the given schemas
Thanks
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Anitha Lingam:
Jayadev,
Can you please tell how to use the schema validator XSV to validate the xml documents against the given schemas
Thanks

Hope you won't mind if i reply.
One easy way is go to the directroy where the xsv.exe is located(usually at /xsv12/ directory)
Now store ur xml and/or xsd file in this directory (say foo.xml )
then open the command prompt at this location.
typexsv -o result.xml -s xsv.xsl foo.xml
Now open result.xml in IE or mozilla u will see the result of the validation.
The another way is to use it online at http://www.w3.org/2001/03/webdata/xsv
Regards
Balaji


Spritle Software Blogs
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Balaji,
Thanks for the reply. I learnt something from it. I generally use it as "xsv test.xml" and try to see the result on the screen. With the stuff u gave, we can see it in an output file and that is really convenient.
Regards,
Jayadev.
patrick gee
Greenhorn

Joined: Sep 30, 2002
Posts: 9
Hi folks,
I try to validate the bookstore.xsd file thr' online it says "NO error".
But when i try to do that thr' command prompt
It says parser error... crash = "true" &
bug = "validator crashed during target reading".
Why is that?
I try to do store the output in result.xml file like balaji told, there is nothing get stored even error msg.
Help me with this!
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
The best thing in think is to do it locally thru the command prompt. If you can give the code for xml and the schema file in your reply, i'll try to figure out what's wrong with that.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by patrickgee:
Hi folks,
I try to validate the bookstore.xsd file thr' online it says "NO error".
e with this!

Here u r trying to validate the XSD so u need to change the command option with -i
for example to validate a schema foo.xsd
use
xsv -o result_schema.xml -s xsv.xsl -i foo.xsd
BYW patrickgee plz read the message from John Wetherbie
patrick gee
Greenhorn

Joined: Sep 30, 2002
Posts: 9
Thanks balaji,
It WORKS!
Reg. John lot of naming policies in ranch!everything is already reserved.
i cant find any useless display name, which i can remember other than my name! Sorry now i changed that.
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
thanks for the xml resources.
Anitha Lingam
Ranch Hand

Joined: Apr 21, 2002
Posts: 38
Balaji and Jayadev, Thanks to both of you.
patrick gee
Greenhorn

Joined: Sep 30, 2002
Posts: 9
Hi there,
Can u guys tell me any other good resources for DOM & SAX.
For XML certification do i have to concentrate more for SOAP & WSDL?
What kind of questions can i expect from these 2?
Thanks for ur time.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
xmlbeginner,
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.
PS: Quote from the naming policy:

For your publicly displayed name, use a first name, a space, and a last name. Obviously fictitious names or improperly formatted names may be locked out.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fresher ! need help