Click here to Skip to main content
15,861,168 members
Home / Discussions / XML / XSL
   

XML / XSL

 
QuestionHow ti create sitemap in xml? Pin
JMecier25-Apr-10 0:59
JMecier25-Apr-10 0:59 
AnswerRe: How ti create sitemap in xml? Pin
User 171649225-Apr-10 1:11
professionalUser 171649225-Apr-10 1:11 
GeneralRe: How ti create sitemap in xml? Pin
JMecier27-Apr-10 3:57
JMecier27-Apr-10 3:57 
QuestionWord Formatting Pin
Mahesh Kulkarni14-Apr-10 0:09
Mahesh Kulkarni14-Apr-10 0:09 
Questionbuilding an XML page Pin
Farraj13-Apr-10 5:26
Farraj13-Apr-10 5:26 
AnswerRe: building an XML page Pin
Estys14-Apr-10 1:01
Estys14-Apr-10 1:01 
GeneralRe: building an XML page Pin
Farraj14-Apr-10 1:20
Farraj14-Apr-10 1:20 
GeneralRe: building an XML page Pin
Estys14-Apr-10 2:22
Estys14-Apr-10 2:22 
Your approach with XmlDocument in itself works, I tried your code.
What you need to to there is first checking if the file exists and if so xDoc.Load(<file>);.
FileInfo fi1 = new System.IO.FileInfo(@"c:\temp\chores2.xml");

if (!fi1.Exists)
{
    XDoc.Load(@"c:\temp\chores2.xml")
}
else
{
    XmlElement XElemRoot = XDoc.CreateElement("chores");
    XDoc.AppendChild(XElemRoot);
}



To add a job to a particular day you need to find the node with the right title :
XDoc.SelectSingleNode("descendant::day[@title='YourTitle']");


You can now add your jobs to it.

About option 2, MS has a utility called XSD. On my PC it's in :
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\xsd.exe


With your xml you can generate an xsd, and with the xsd you can generate a .cs file.
It has all the classes and attributes you need. You can and should edit it to suit your needs.
The only thing left to do is write a serializer and a deserializer.
The code would look something like this (I removed all attributes)
public partial class chores {
    
    private choresDay[] itemsField;
    
    public choresDay[] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
        }
    }
}

public partial class choresDay {
    
    private choresDayJob[] jobField;
    
    private string titleField;
    
    public choresDayJob[] job {
        get {
            return this.jobField;
        }
        set {
            this.jobField = value;
        }
    }
    
    public string title {
        get {
            return this.titleField;
        }
        set {
            this.titleField = value;
        }
    }
}

public partial class choresDayJob {
    
    private string aField;
    
    private string bField;
    
    private string cField;
    
    private string dField;
    
    public string a {
        get {
            return this.aField;
        }
        set {
            this.aField = value;
        }
    }
    
    public string b {
        get {
            return this.bField;
        }
        set {
            this.bField = value;
        }
    }
    
    public string c {
        get {
            return this.cField;
        }
        set {
            this.cField = value;
        }
    }
    
    public string d {
        get {
            return this.dField;
        }
        set {
            this.dField = value;
        }
    }
}

You would use it :


            chores chores = new chores();
            chores.Items  = new choresDay[];
            chores.Items[0] = new choresDay;;
            chores.Items[0].job = new choresDayJob[];
            chores.Items[0].job[0] = new choresDayJob();
            chores.Items[0].job[0].a = this.a;
            chores.Items[0].job[0].b = this.b;


Good luck!
GeneralRe: building an XML page Pin
Farraj14-Apr-10 6:07
Farraj14-Apr-10 6:07 
GeneralRe: building an XML page Pin
Estys14-Apr-10 22:52
Estys14-Apr-10 22:52 
GeneralRe: building an XML page Pin
Farraj15-Apr-10 0:46
Farraj15-Apr-10 0:46 
AnswerRe: building an XML page Pin
Farraj16-Apr-10 4:26
Farraj16-Apr-10 4:26 
GeneralRe: building an XML page Pin
Estys16-Apr-10 6:04
Estys16-Apr-10 6:04 
GeneralRe: building an XML page Pin
Farraj24-Apr-10 9:46
Farraj24-Apr-10 9:46 
QuestionImage in XML Pin
farokhian10-Apr-10 5:08
farokhian10-Apr-10 5:08 
AnswerRe: Image in XML Pin
daveyerwin10-Apr-10 10:29
daveyerwin10-Apr-10 10:29 
Questionhey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
anubir7-Apr-10 9:44
anubir7-Apr-10 9:44 
AnswerRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
Stuart Dootson7-Apr-10 14:22
professionalStuart Dootson7-Apr-10 14:22 
GeneralRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
anubir8-Apr-10 3:07
anubir8-Apr-10 3:07 
GeneralRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
anubir8-Apr-10 3:08
anubir8-Apr-10 3:08 
GeneralRe: hey I need some help with my coding...... I have an xml and a dtd but they dont validate... can someone help me please? Pin
Stuart Dootson8-Apr-10 4:49
professionalStuart Dootson8-Apr-10 4:49 
QuestionXML File is not updated in IE browser Pin
vdtrip7-Apr-10 8:40
vdtrip7-Apr-10 8:40 
QuestionGenerating a new XML file starting with a XML file and applyng XSLT Pin
FJJCENTU5-Apr-10 7:32
FJJCENTU5-Apr-10 7:32 
AnswerRe: Generating a new XML file starting with a XML file and applyng XSLT Pin
FJJCENTU5-Apr-10 8:56
FJJCENTU5-Apr-10 8:56 
QuestionCompiling an XML database with an application Pin
brdavid24-Mar-10 21:19
brdavid24-Mar-10 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.