Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Reading XML in C# -


i have following xml

<objects>     <object>         <viewangle>90</viewangle>         <viewmode>thirdperson</viewmode>         <top>50</top>         <left>100</left>     </object> </objects> 

i have following code read xml

           xmldatadocument doc = new xmldatadocument();            doc.load(xmlpath);            xmlelement root = doc.documentelement;            xmlnodelist nodes = root.selectnodes("/objects/object");            foreach (xmlnode node in nodes)            {                 if (node.innerxml.contains("view"))                 {                   string viewtype=node["view"].innertext;                   //..... other stuffs                 }                 if (node.innerxml.contains("viewangle"))                 {                   string viewangle=node["viewangle"].innertext;                   //..... other stuffs                 }                 if (node.innerxml.contains("viewmode"))                 {                   string viewmode=node["viewmode"].innertext;                   //..... other stuffs                 }            } 

above code working fine if xml contains 1 more tag i.e. <view>3dview</view>. if not contains view tag, produces error.

the innerxml.contains() simple string method checks sub-string present in string or not.

in case contains("view") returns true view present in viewangle , in viewmode why going inside if block of view when tries read node["view"], produces error view node not exists in xml.

how resolve error?

you missing fact xml structured data, not string. completely wrong approach:

if (node.innerxml.contains("view")) {   // ... } 

you want this:

xmlnode child = node.selectsinglenode("./view"); if (child != null) {   // 'child' ... } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -