Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 16
Registered: ‎06-27-2012
My Device: 9900
My Carrier: Orange
Accepted Solution

I really need a help from professional in XML Parsing to XML Document, or I want to read XML

Hello everyone,

 

I really seek your gentle help. I am suffering since two days ago. I am working on Blackberry java app. I have xml file located in "file:///store/home/user/myNotes.xml"

 

I want to be able to parse XML into XMLDocument to deal with teh NodeList and ChildNode.

 

I am always getting Uncaught Exception RunTimeError

 

NOTE the following please:

1- My JDK is 1.7.0.5.5 (SE) only

2- I dont have "XMLSerializer", Or "Transformer", Or "TransformerFactory", Or "KXML"

3- All what I want is simply to be able to read XML located above and parse it to XMLDocument.

 

Find my Java code below:

=====================================================================================

 private void parseXmlFile() throws RuntimeException{
        try {

            XMLDocument dom = null;
            private static final String fileN = "file:///store/home/user/myNotes.xml";
            FileConnection fc = (FileConnection)Connector.open(fileN);
            fc.openDataInputStream();
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            InputStream is = getClass().getResourceAsStream(fileN);
            dom = builder.parse(is);
    
        }catch(Exception pce) {
            Dialog.alert(pce.toString());
        }
        
    }

======================================================================

 

End of my Code

 

Thank you very much for your time reading and replying to help me.

I really appreciate that.

Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: I really need a help from professional in XML Parsing to XML Document, or I want to read XML

[ Edited ]

There is a xmlDemo that comes with SDK. you can import it and check it.

Also, there are ton of codes available on net.

 

check few of these on this forum

http://supportforums.blackberry.com/t5/Java-Development/Use-the-XML-Parser/ta-p/445210

http://supportforums.blackberry.com/t5/Java-Development/xml-parsing-using-dom/m-p/547221#M111026

http://supportforums.blackberry.com/t5/Java-Development/Help-with-parsing-XML-XMLParseDemo-java/td-p...

http://supportforums.blackberry.com/t5/Java-Development/Xml-parsing-using-sax-parser/m-p/1651191#M19...

 

Thanks

Abhinav Tyagi

 

 

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Highlighted
Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: I really need a help from professional in XML Parsing to XML Document, or I want to read XML

Hi

Can you share you xml code.

Thanks
Pawan
Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: I really need a help from professional in XML Parsing to XML Document, or I want to read XML

Hello

 

Try this code. here you will get the Document obj.

 

public static Document getXMLDocument() throws IOException
	{
		FileConnection fconn;
		InputStream input = null;
		try
		{
			fconn = (FileConnection)Connector.open( "file:///store/home/user/myNotes.xml");
			if(fconn.exists()==true)
			{
				input = fconn.openInputStream();
			}
		}
		catch(Exception e)
		{
			System.out.println("Not able to convert byte.");
		}
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = null;
		try {
			builder = factory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Document document = null;
		try {
			document = builder.parse(input);
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		document.getDocumentElement().normalize();
		return document;
	}

 

Henceforth,

use like this.

 

Document doc = getXMLDocument();

 

Nodelist nodeList = doc.getElementsByTagName("<tagName>");

 

Thanks

Pawan

 

Contributor
Posts: 16
Registered: ‎06-27-2012
My Device: 9900
My Carrier: Orange

Re: I really need a help from professional in XML Parsing to XML Document, or I want to read XML

Dear All,

Greetings and thanks from the bottom of my heart. It works. My problem was missing the "Normalization".

Thank you again I raelly appreciated your valuable input.