[Cosmo-dev] VCard Parsing in Cosmo

Vinubalaji Gopal vinu at osafoundation.org
Wed Jul 19 12:50:56 PDT 2006


On Wed, 2006-07-19 at 11:57 -0700, Brian Moseley wrote:

> i'm not sure what you mean. can you give an example? isn't the point
> of using the dom that you don't need to do the parsing yourself?

This is how the DOM is created.
DomParser parser = new DomParser();
DocumentBuilderFactory.newDocumentBuilder().newDocument();
Document document = new DocumentImpl();
parser.parse(new FileInputStream(args[i]), document);

If the dom is serialized to a XML file it looks like:

<addressBook>
    <vcard>
        <type name="FN">
            <value>
                <text>Yann Duponchel</text>
            </value>
        </type>
        <type name="N">
            <value>
                <structuredItem>
                    <listItem>
                        <text>Duponchel</text>
                    </listItem>
                </structuredItem>
                   .
               .    .
        </type>
    </vcard>
</addressBook>

The java objects used by the author (or my implementation) does an XPath
query on this DOM to find entries for FN, N, etc. 

A Name could be like
N:Duponchel;Yann
and is parsed as

 <type name="N">
            <value>
                <structuredItem>
                    <listItem>
                        <text>Duponchel</text>
                    </listItem>
                </structuredItem>
                <structuredItem>
                    <listItem>
                        <text>Yann</text>
                    </listItem>
                </structuredItem>
                <structuredItem>
                    <listItem>
                        <text/>
                    </listItem>
                </structuredItem>
                <structuredItem>
                    <listItem>
                        <text/>
                    </listItem>
		</structuredItem>
  </type>

My XPath query would reconstruct N:Duponchel;Yann and I thought why not
just use the original VCARD to take this name value pairs. 





More information about the cosmo-dev mailing list