Search code examples
javaxmlsax

Parse XML files with strange syntax


First: Is there a name for this type of XML syntax? Second: How can I parse XML file like this with Java, I have looked on som SAX examples, but cant figure out how to parse XML files with this type of syntax. Please give me som advice.

<Company>
    <staff Firstname="yong" Lastname="mook" Nickname="mkyoung" Salary="10000" />
    <staff Firstname="low" Lastname="yin fong" Nickname="fong fong" Salary="2000" />
</Company>

Solution

  • The dom4j library is great if your XML all fits into memory.

    Usage:

    Document doc = DocumentHelper.parseText(xmlString);
    

    Note: use the 1.6.1 version, as the 2.0 version is not active and development stopped in alpha.