Calendar notes in .xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bojan.pikl@gmail.com

    Calendar notes in .xml

    Hi, I am making a simple calendar. I would like to have the ability of
    notes. I was thinking of using this kind of notes.xml file. I am not
    sure how to operate with nodes. I just need to access something like
    SelectNode("/NOTES/y"+Year+"/m"+Month+"/d"+Day); (I'd get
    /NOTES/y2006/m5/d18) and than I'd read what is in there. Can anyone
    help please?
    <NOTES>
    <y2006>
    <m4>
    <DAYS>1,2,13</DAYS>
    <DESCRIPTION>
    <d1>New Year</d1>
    <d2>Day after New Year</d2>
    <d13>Special day :)</d13>
    </DESCRIPTION>
    </m4>
    <m5>
    <DAYS>1,30</DAYS>
    <DESCRIPTION>
    <d1>New Year</d1>
    <d30>Special day :)</d30>
    </DESCRIPTION>
    </m5>
    </y2006>
    <y2007>
    <m2>
    <DAYS>5,28</DAYS>
    <DESCRIPTION>
    <d5>Service</d5>
    <d28>Change tyers.</d28>
    </DESCRIPTION>
    </m2>
    </y2007>
    </NOTES>

  • Markus Stoeger

    #2
    Re: Calendar notes in .xml

    bojan.pikl@gmai l.com wrote:
    Hi, I am making a simple calendar. I would like to have the ability of
    notes. I was thinking of using this kind of notes.xml file. I am not
    sure how to operate with nodes. I just need to access something like
    SelectNode("/NOTES/y"+Year+"/m"+Month+"/d"+Day); (I'd get
    /NOTES/y2006/m5/d18) and than I'd read what is in there. Can anyone
    help please?
    Have a look at the XmlDocument class. It provides the two methods called
    SelectSingleNod e and SelectNodes that you can pass your XPath expression
    to. Does that help?
    <NOTES>
    <y2006>
    <m4>
    Instead of naming your elements like that, maybe it would be nicer to
    use attributes? Like:

    <Notes>
    <Note Year="2006" Month="4" Day="1">New Year</Note>
    <Note Year="2006" Month="4" Day="2">Day after New Year</Note>
    <Note Year="2006" Month="4" Day="13">Specia l day :)</Note>
    </Notes>

    ... you can query that with XPath too:
    /Notes/Note[Year="2006" and Month="4" and Day="13"]

    hth,
    Max

    Comment

    • Markus Stoeger

      #3
      Re: Calendar notes in .xml

      Markus Stoeger wrote:
      /Notes/Note[Year="2006" and Month="4" and Day="13"]
      that should have been:
      /Notes/Note[@Year="2006" and @Month="4" and @Day="13"]

      Max

      Comment

      • bojan.pikl@gmail.com

        #4
        Re: Calendar notes in .xml

        Hi could someone provide more information and perhaps an example.
        Thank you guys

        Comment

        • Markus Stoeger

          #5
          Re: Calendar notes in .xml

          bojan.pikl@gmai l.com wrote:
          Hi could someone provide more information and perhaps an example.
          Thank you guys
          Have you read the MSDN docs for the methods I mentioned? They provide
          lots of information and examples.

          Max

          Comment

          • bojan.pikl@gmail.com

            #6
            Re: Calendar notes in .xml

            Hi, yes I have but I am not sure.

            My code looks like:
            //Start code
            XmlDocument doc = new XmlDocument();
            doc.Load("notes .xml");

            XmlNodeList nodeList;
            XmlNode root = doc.DocumentEle ment;

            nodeList=root.S electNodes("/Notes/note[@Year="+this.Ye ar.ToString()+"]");

            //Save notes to a. A will be displayed later.
            foreach (XmlNode note in nodeList)
            {
            a=note.InnerTex t.ToString();
            }
            //End code

            And it does not works. The XML looks like you suggested. I am not sure
            about XPath. I think it is not correct. Could you tell me some more
            info about this?

            Thank you,
            Bojan

            Comment

            • Markus Stoeger

              #7
              Re: Calendar notes in .xml

              bojan.pikl@gmai l.com wrote:
              Hi, yes I have but I am not sure.
              >
              My code looks like:
              nodeList=root.S electNodes("/Notes/note[@Year="+this.Ye ar.ToString()+"]");
              XPath is case sensitive. Are you sure your Xml element is called "note"
              and not "Note"? Makes a difference! Otherwise it looks good.
              //Save notes to a. A will be displayed later.
              foreach (XmlNode note in nodeList)
              {
              a=note.InnerTex t.ToString();
              What is 'a'? Are you sure you don't need '+=' instead of '='?
              And it does not works. The XML looks like you suggested. I am not sure
              about XPath. I think it is not correct. Could you tell me some more
              info about this?
              Here is a short introduction to xpath that explains everything one has
              to know about about it: http://www.w3schools.com/xpath/xpath_intro.asp

              hth,
              Max

              Comment

              • bojan.pikl@gmail.com

                #8
                Re: Calendar notes in .xml

                Hi Markus,

                it now works. Thank you for helping me.

                Now I have to make a method that will insetred new notes into XML
                database.
                Could you tell me some methods for this?

                Thanks again,
                Bojan

                Comment

                • bojan.pikl@gmail.com

                  #9
                  Re: Calendar notes in .xml

                  I found an example:

                  XmlNode root = doc.DocumentEle ment;
                  XmlElement elem = doc.CreateEleme nt("note");
                  elem.InnerText= "Visit doctor at 5 PM";
                  root.InsertAfte r(elem, root.FirstChild );

                  But I dont know how to setup a parametrs (Year, Month, Day).

                  Comment

                  • Markus Stoeger

                    #10
                    Re: Calendar notes in .xml

                    bojan.pikl@gmai l.com wrote:
                    I found an example:
                    >
                    XmlNode root = doc.DocumentEle ment;
                    XmlElement elem = doc.CreateEleme nt("note");
                    elem.InnerText= "Visit doctor at 5 PM";
                    root.InsertAfte r(elem, root.FirstChild );
                    >
                    But I dont know how to setup a parametrs (Year, Month, Day).
                    These values are called xml attributes. Have a look at the documentation
                    of the method XmlElement.SetA ttribute(string name, string value):

                    elem.SetAttribu te("Year", "2006");

                    There's also GetAttribute to read the value back.

                    hth,
                    Max

                    Comment

                    Working...