0

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>
3
  • 3
    That's not a strange syntax. Those are attributes. w3schools.com/xml/xml_attributes.asp Commented May 2, 2013 at 16:52
  • 1
    Please see <stackoverflow.com/questions/9008864/java-read-xml-attributes> and / or search for how to read XML attributes. Commented May 2, 2013 at 16:54
  • 1
    Actually, parsing XML that makes extensive use of attributes using SAX is much easier than parsing XML that puts the same information in child elements, because an element and all its attributes are delivered in a single call. Perhaps you need a better learning strategy than "looking at examples": why not read a book such as Elliotte Rusty Harold's, which will tell you all you need to know? Commented May 2, 2013 at 22:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.