Xerces Parser Help needed URGENT

Hi, I am trying to write a parser that can parse a XML file, and then use RSS to make a feed of my own XML schemas.
I need help in the Xerces XML parser part. Does anyone have sample code for using Xerces XML parser in parsing a XML file, by tagnames ..etc , or maybe tell me how I can parse XML file such as :
<RootNode>
 <List name = "something">
     <Item>item a</Item>
     <Description>Something</Description>
     <Prices>
        <Price>10</Price>
        <Price>11</Price>
     </Prices>
 </List>
</RootNode>

Where i will have multiple List,
I want to parse the List-Name, and the Item, description, prices(and all the individual Price)

The xml file can be located on disk or on web.

I read up on the RSS feed creation on java.sun.com especially the rome library.

How do I create feed that can be displayed as :

<List name = "something">
     <Item>item a</Item>
     <Description>Something</Description>
     <Price>something</Price>
</List>


Thanks for your help,
if you have sourcecode and would rather like to email please email to me at
<e-mail removed from Venabili>
(If you do email please let me know you emailed)




lordianoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You could use XPath to get your List nodes:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File(args[0]));
XPath xpath = XPathFactory.newInstance().newXPath();
final String findList = "//List";
NodeList nodeList = (NodeList) xpath.evaluate(findList, document, XPathConstants.NODESET);
for(int i = 0;i < nodeList.getLength();i++) {
      //process
}

Step-by-step on writing feeds

http://wiki.java.net/bin/view/Javawsxml/Rome04TutorialFeedWriter

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VenabiliCommented:
lordiano,

Please do not post your e-mail in questions -- all the communication should be lead on the site. I removed it from here.

Thanks
Venabili
Java Page Editor
0
sudhakar_koundinyaCommented:
Although I haven't tested

this might help you


import org.xml.sax.AttributeList;
import org.xml.sax.HandlerBase;
import org.xml.sax.Parser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.ParserFactory;
import org.xml.sax.XMLReader;
import org.apache.xerces.parsers.SAXParser;
import java.io.*;




import java.util.*;



public class SAXParserXercesTest1
     extends HandlerBase { //implements org.xml.sax.ContentHandler

  /**
   * handler method, this is invoked in starting of every element while reading the XML document
   */

             public void startElement(String name, AttributeList attrs)
      {

      node=name;
      if(node.equals("List"))
            {
                  list=new AList();
                  list.name = atts.getName(0);

            }

  }

  /**
   * handler method, this is invoked in ending of every element while reading the XML document
   */
    public void endElement(String name)
    {
              if(node.equals("List"))
            {
                        lists.add(list);
            }
    } //

  /**
   * handler method, this is invoked in after startElement while reading the XML document
   */
   public void characters(char ch[], int start, int len){

    String str = new String(ch, start, len);

            if(node.equals("Item"))
         {
                  list.item=str;
         }
         if(node.equals("Description"))
         {
               list.desc=str;
         }
                  if(node.equals("Price"))
         {
                    list.prices.add(str);
         }

  }

 

  public static void main(String s[]) throws Exception
      {
                                 long startTime=System.currentTimeMillis() ;
             
        SAXParser parser = new SAXParser();
        SAXParserXercesTest1 handler = new SAXParserXercesTest1();
              parser.setDocumentHandler(handler);
        parser.parse("c:/a111.xml");
       
            


             long endTime=System.currentTimeMillis() ;
             System.out.println("Xerces Sax Parser  : Time taken to parse the document for "+s[0]+" times is :"+((endTime-startTime)/1000));

      }

      private Vector getITemLists()
      {
            return lists
      }

String node;
AList list=null;
Vector lists=new Vector();
}



class AList
{
      private String name;
      private String item;
      private String desc;
      private Vector prices;
};
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

MogalManicCommented:
I would recommend using JAXP (Part of JDK 1.4 and downloadable from SUN).  The code will be something like this:

DocumentBuilder build=DocumentBuilderFactory.newDocumentBuilder();
Document doc=build.parse(xmlFileName);
...
NodeList listNodes=doc.getElementsByTagName("List-Name ");
for(i=0;i<listNodes.getLength();i++) {
   Element parElement=(Element) listNodes.item(i);
   AList list=new AList();

   //Get the  Item, description, prices nodes
   list.setItem(parElement.getElementsByTagName("Item").item(0).getFirstChild().getNodeValue());
   list.setDescription(parElement.getElementsByTagName("description").item(0).getFirstChild().getNodeValue());
      ...extract the price node just like you did list-name


}


Also check out this thread:
http://www.experts-exchange.com/Programming/Q_21194046.html
0
lordianoAuthor Commented:
When I create Feed using ROME library, How can i create it so that it will have custome tag names?
I am creating it like :

entry = new SyndEntryImpl();
entry.setTitle("Rome v0.1");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
description = new SyndContentImpl();
description.setType("application/xml");
description.setValue("Initial release of Rome");
entry.setDescription(description);
entries.add(entry);
...

but this would be displayed as
<entry>
    <title> .... </title>
    <link>.... </link>
    <summary type = ............../>
</entry>

Is there a way I can rename the tag "entry" to something else?
and is there a way I can create custom tag other than title, link, entry..???

I will split points accordingly THANKS a lot for the help
0
CEHJCommented:
Check the dtd or schema for the xml used - that will tell you what you can and can't use
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.