c12
c12

Reputation: 9827

Java XML Parsing Standards

Has anyone ever done any type of XML paring with elements that have dashes in the names? I don't think its possible, any ideas?

<Person-Response>
   <First-Name> 3119043033121014002</First-Name>
   <Last-Name> 3119043033121014002</Last-Name>
</Person-Response>

Upvotes: 0

Views: 1759

Answers (5)

forty-two
forty-two

Reputation: 12817

If this is a questin regarding XML to java mapping then JAXB can handle it:

@XmlRootElement(name = "Person-Response")
public class PersonResponse {
    @XmlElement(name = "First-Name")
    String firstName;
    @XmlElement(name = "Last-Name")
    String lastName;
}

Upvotes: 3

Shimi Bandiel
Shimi Bandiel

Reputation: 5747

It is a legal XML and any parser could parse it.

Regarding Java, you have the JAXP API support for parsing this XML in either DOM, SAX or StAX.

Upvotes: 0

Uwe
Uwe

Reputation: 436

Regarding the dashes, see the official XML recommendation of the W3C:

Document authors are encouraged to use names which are meaningful words or combinations of words in natural languages, and to avoid symbolic or white space characters in names. Note that COLON, HYPHEN-MINUS, FULL STOP (period), LOW LINE (underscore), and MIDDLE DOT are explicitly permitted.

Upvotes: 3

Dhanush Gopinath
Dhanush Gopinath

Reputation: 5749

There should not be any problem because of the dashes. But it is an invalid xml as per the reason mentioned by Per Norman

Upvotes: 0

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81724

This is legal XML; any compliant parser should have no problems with it.

Upvotes: 2

Related Questions