Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

XML Tokenizer Question

Thread view: 
Tony - 01 Aug 2006 19:25 GMT
Hello,
I'm trying to build a simple Tokenzier For XML:
I have the following String tat I get from the serverand want to build
a method that takes "property name" and returns it's value.

for example:
<dictionary>
    <Status>1</Status>
    <Reason>0</Reason>
    <Key>JFKDL54GFDYU85T43NJKGH89N543KGFD</Key>
</dictionary>

if I call GetVaule("Key"); I want to get back as string
"JFKDL54GFDYU85T43NJKGH89N543KGFD".

I tried to use Kxml parser but it has a problem with unicode / UTF-8
coding. (especailly with hebrew and arabic)

same thing about Nanoxml
note that my XML file is very simple and small (it won't be more than
5-6 properties)

any help ?
Oliver Wong - 01 Aug 2006 21:03 GMT
> Hello,
> I'm trying to build a simple Tokenzier For XML:
[quoted text clipped - 19 lines]
>
> any help ?

   Is the keyword "Tokenizer" important? From your description of the
problem, it doesn't sounds like you want a tokenizer at all.

   Did you try using Java's DOM or SAX API and just accepting whatever
default XML parser it uses?

   - Oliver
Tony - 02 Aug 2006 08:04 GMT
Hey,
Sorry, I ment for Parser and not Tokenizer.
my mistake.
Flávio Barata - 02 Aug 2006 12:40 GMT
Try this Java 1.5 code:

    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory factory1 =
DocumentBuilderFactory.newInstance();
        DocumentBuilder builder1 = factory1.newDocumentBuilder();
        Document doc1 = builder1.parse(new File("yourFileToBeParsed.xml"));
        System.out.println("> " +
getText(doc1.getElementsByTagName("Key").item(0)));
    }

    private static String getText(Node node) {
        StringBuilder sb = new StringBuilder();
        NodeList nodeList = node.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node n = nodeList.item(i);
            if (n.getNodeType() == Node.TEXT_NODE) {
                sb.append(n.getNodeValue().trim());
            }
        }
        return sb.toString();
    }

-
Flavio Santos

> Hey,
> Sorry, I ment for Parser and not Tokenizer.
> my mistake.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.