locked
How to read xml file using c# in windows mobile 6.0 apps ? RRS feed

  • Question

  • Hi

    while xml reading i'm facing problem like "value doesn't fallen with in the expected range".

    can u pls help for this problem.

    Monday, September 6, 2010 12:16 PM

Answers

  • I wouldn't suggest putting it directly on the storage card or in the program files folder and hard coding that path. If you do your program will fail to find the file the first time it runs on a localized device or when some one installs the program in a location other than what you were expecting. 

     

    Include the XML file in your project. If you've already made the XML file you can add it to the project by right-clicking on on the project and selecting "Add Existing Item." Once the file is part of your project you can mark it as "Content" and then it will deploy with your program. To mark it as content right-click on the file and select "Properties." A properties editor will display (usually in the lower-right corner of Visual Studio, but if you've changed your layout it could be some where else). Set the build action to "Content" and for the copy option select "Copy if newer". 

     

    To detect the path of the file at runtime you can use the following code. 

    string programFolder = Path.GetDirectoryName(this.GetType().Assembly.GetModules()[0].FullyQualifiedName);
    string xmlFileFullPath = Path.Combine(programFolder, "xmlFileName.xml");
    
    Using the data set to load an XML file is a valid way of doing so but it won't work for all XML files. There are occasions when you'll come across an XML format for which the dataset cannot infer a schema (in which case it will fail to load).  If you find that the DataSet isn't appropriate for the XML file you are processing then post a snippet of the XML file here. It will be helpful in presenting other appropriate ways to read it.


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Marked as answer by warrentang Friday, September 10, 2010 3:22 AM
    Tuesday, September 7, 2010 12:23 PM

All replies

  • Are you reading a well know XML based format or is this something completly custom?

    What method are you using to read the XML document?


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    Monday, September 6, 2010 12:20 PM
  • Hi  i wrote like this.but getting above error.""value doesn't fallen with in the expected range"."

     

     

     

    while (reader.Read())

     

    XmlNodeType nodetype = reader.NodeType;

     

    switch (nodetype)

     

    {

    }

    }

     

    {

     

     

    XmlTextReader reader = new XmlTextReader(AnimalsApplication.Resource1.XMLFile2);
    Monday, September 6, 2010 12:28 PM
  • Hi,

    Try with the follwoing code for Reading XMl file in WindowMobile

     

                    DataSet pdads = new DataSet();


                    pdads.ReadXml("Storage Card/xmlfileName.xml ");


                string pdaid = pdads.Tables[0].Rows[0]["Pda_id"].ToString();


    In the above code,I save (or) stored my XMlfile in Mobile Sotrage Card .


    PS.Shakeer Hussain Hyderabad
    Tuesday, September 7, 2010 8:47 AM
  • i want to test my app in mobile emulator .then ,where to place that xml file?
    Tuesday, September 7, 2010 9:02 AM
  • you can place it  in Program Files folder as follows

     

    pdads.ReadXml(" Program Files/xmlFileName.xml ");


    PS.Shakeer Hussain Hyderabad
    Tuesday, September 7, 2010 9:04 AM
  • I wouldn't suggest putting it directly on the storage card or in the program files folder and hard coding that path. If you do your program will fail to find the file the first time it runs on a localized device or when some one installs the program in a location other than what you were expecting. 

     

    Include the XML file in your project. If you've already made the XML file you can add it to the project by right-clicking on on the project and selecting "Add Existing Item." Once the file is part of your project you can mark it as "Content" and then it will deploy with your program. To mark it as content right-click on the file and select "Properties." A properties editor will display (usually in the lower-right corner of Visual Studio, but if you've changed your layout it could be some where else). Set the build action to "Content" and for the copy option select "Copy if newer". 

     

    To detect the path of the file at runtime you can use the following code. 

    string programFolder = Path.GetDirectoryName(this.GetType().Assembly.GetModules()[0].FullyQualifiedName);
    string xmlFileFullPath = Path.Combine(programFolder, "xmlFileName.xml");
    
    Using the data set to load an XML file is a valid way of doing so but it won't work for all XML files. There are occasions when you'll come across an XML format for which the dataset cannot infer a schema (in which case it will fail to load).  If you find that the DataSet isn't appropriate for the XML file you are processing then post a snippet of the XML file here. It will be helpful in presenting other appropriate ways to read it.


    Joel Ivory Johnson | http://www.j2i.net | Device Application Development MVP
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Marked as answer by warrentang Friday, September 10, 2010 3:22 AM
    Tuesday, September 7, 2010 12:23 PM