Tuesday, October 25, 2011

invalid expanded name (LINQ to XML)

Assuming I am reading this xml file using XLINQ.
I encountered an error that says invalid expanded name. As i go through
this xml file, i found a node images that contains element tags. The parent
node is also an element tag. Since i don't use the images tag, I simply remove it using string manipulations. Below is the xml file and the solution:
1:  <element>  
2:        <id>2768687195</id>  
3:        <title>Customer Service Representative</title>  
4:        <body>Do you dream of being your own boss and choosing the work you   
5:  do, when you work and who you work for?   
6:        </body>  
7:        <url>http://jobs.myjob.careercenter-servicecrew.html</url>  
8:        <category>  
9:          <id>job/customer_service</id>  
10:          <name>Customer Service &amp; Call Center Jobs</name>  
11:        </category>  
12:        <source>  
13:          <id>www</id>  
14:          <name>Oodle</name>  
15:        </source>  
16:        <location>  
17:          <citycode>can:on:ajax</citycode>  
18:          <name>Ajax</name>  
19:          <state>ON</state>  
20:          <country>CAN</country>  
21:          <latitude>43.8610</latitude>  
22:          <longitude>-79.0292</longitude>  
23:        </location>  
24:        <images>  
25:          <element>  
26:            <src>http://i.oodleimg.com/item/2768687195u_0s?1318626136</src>  
27:            <width>100</width>  
28:            <height>75</height>  
29:            <alt>Customer Service Representativ</alt>  
30:            <num>0</num>  
31:            <size>s</size>  
32:          </element>  
33:          <element>  
34:            <src>http://i.oodleimg.com/item/2768687195u_0m?1318626136</src>  
35:            <width>144</width>  
36:            <height>108</height>  
37:            <alt>Customer Service Representativ</alt>  
38:            <num>0</num>  
39:            <size>m</size>  
40:          </element>  
41:          <element>  
42:            <src>http://i.oodleimg.com/item/2768687195u_0l?1318626136</src>  
43:            <width>208</width>  
44:            <height>156</height>  
45:            <alt>Customer Service Representativ</alt>  
46:            <num>0</num>  
47:            <size>l</size>  
48:          </element>  
49:          <element>  
50:            <src>http://i.oodleimg.com/item/2768687195u_0x?1318626136</src>  
51:            <width>100</width>  
52:            <height>100</height>  
53:            <alt>Customer Service Representativ</alt>  
54:            <num>0</num>  
55:            <size>x</size>  
56:          </element>  
57:          <element>  
58:            <src>http://i.oodleimg.com/item/2768687195u_0j?1318626136</src>  
59:            <width>100</width>  
60:            <height>100</height>  
61:            <alt>Customer Service Representativ</alt>  
62:            <num>0</num>  
63:            <size>j</size>  
64:          </element>  
65:        </images>  
66:        <ctime>1318626135</ctime>  
67:        <paid>Yes</paid>  
68:        <revenue_score>6</revenue_score>  
69:        <user>  
70:          <id>51527855</id>  
71:          <url>http://www.oodle.com/seller/arise-virtual-solutions/51527855/</url>  
72:          <name>Arise Virtual Solutions</name>  
73:          <photo>http://i.oodleimg.com/a/img_profilephoto.gif</photo>  
74:        </user>  
75:        <attributes>  
76:          <company>Arise Virtual Solutions</company>  
77:          <fee>No</fee>  
78:          <full_time>Full Time</full_time>  
79:          <has_photo>Thumbnail</has_photo>  
80:          <job_title>Customer Service Representative</job_title>  
81:          <user_id>51527855</user_id>  
82:        </attributes>  
83:      </element>  
Code:
for (int ctr = 0; ctr < ListingSource.Length; ctr++)  
{  
  if (ListingSource.Contains("<images>"))  
  {  
     int length = (ListingSource.IndexOf("
     </images>") + 9) - ListingSource.IndexOf("
     <images>");  
     ListingSource = ListingSourceRemove  
     ListingSource.IndexOf("<images>"), length);  
     }  
} 

0 comments:

Post a Comment