Hiren Gujarati
Hiren Gujarati

Reputation: 11

how to parse xml file with attributes?

I want to parse this file in Cocoa Application.but no parser for xml work well.Please help for parsing this file or other xml files like this. Thanks... My Xml File is as Under:

Hiren

<property id=\"license\">
  <object> 
     <property id=\"color\">
     <string>red</string>
     </property>
     <property id=\"expiresOn\"> 
      <string>10-10-2010</string>
     </property>
     <property id=\"Note\"> 
      <string>This licence is valid to <[email protected]> until 10-10-2010</string>
     </property>
  </object>
</Property>

Upvotes: 1

Views: 260

Answers (2)

Peter Hosey
Peter Hosey

Reputation: 96323

I want to parse this file in Cocoa Application.but no parser for xml work well.

The parsers work fine. Your input is broken; it isn't valid XML.

There are two things wrong with it:

  1. The quote marks are backslash-escaped. (Maybe you escaped them for Stack Overflow? If so, don't do that.)
  2. The value of the string element within the property#Note element contains unescaped angle brackets.

Your input is broken; therefore, you cannot parse it as XML. If you want to parse XML, you need valid XML to parse.

Upvotes: 4

avpx
avpx

Reputation: 1922

Have you considered using the DOM? A quick Google search shows that Apple's libraries provide a DOM implementation. Then it's just a matter of finding the right Element and calling getAttribute on it to find the values of the various attributes.

Upvotes: 0

Related Questions