basic XML reading question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie

    basic XML reading question

    Hi,

    I am just starting to learn to use XML, so this is a really basic question.

    I have managed to write my XML document to disk, and now want to read it
    back, and get the values from the XML file. My XML file is at the bottom. I
    am assuming that its correct (but I could be wrong)

    What I want to be able to do is just get parts of the xml document, for
    example I only want to get the fields for the content type 'sample1' (the
    below sample has just one contenttype, normally it would have hundreds) I
    would also then want to get the choices for where they exisit for fields.

    Whilst I am sure the answer is straight forward, I have not found an answer
    that i can understand easily.

    Any tips would be great.


    <?xml version="1.0"?>
    <!--Created on 7/30/2008 9:31:54 PM-->
    <libraries>
    <library id="97199410">
    <name>Service Documents</name>
    <ContentType>
    <name>Sample1 </name>
    <Field>
    <name>Content Type</name>
    <Choices>
    <name>Documen t</name>
    </Choices>
    <Choices>
    <name>Folder</name>
    </Choices>
    <Choices>
    <name>Heath</name>
    </Choices>
    </Field>
    <Field>
    <name>Name</name>
    </Field>
    <Field>
    <name>Title</name>
    </Field>
    <Field>
    <name>Documen t Modified By</name>
    </Field>
    <Field>
    <name>Documen t Created By</name>
    </Field>
    <Field>
    <name>ABN</name>
    </Field>
    <Field>
    <name>Legal Name</name>
    </Field>
    <Field>
    <name>Option List</name>
    <Choices>
    <name>Selecti on 1</name>
    </Choices>
    <Choices>
    <name>Selecti on 2</name>
    </Choices>
    <Choices>
    <name>Selecti on 3</name>
    </Choices>
    <Choices>
    <name>Selecti on 4</name>
    </Choices>
    </Field>
    <Field>
    <name>DropDow n Metadata Col</name>
    <Choices>
    <name>Choice1 </name>
    </Choices>
    <Choices>
    <name>Choice2 </name>
    </Choices>
    <Choices>
    <name>Choice3 </name>
    </Choices>
    </Field>
    </ContentType>
    </library>
    </libraries>

  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: basic XML reading question

    Newbie wrote:
    I have managed to write my XML document to disk, and now want to read it
    back, and get the values from the XML file. My XML file is at the
    bottom. I am assuming that its correct (but I could be wrong)
    >
    What I want to be able to do is just get parts of the xml document, for
    example I only want to get the fields for the content type 'sample1'
    (the below sample has just one contenttype, normally it would have
    hundreds) I would also then want to get the choices for where they
    exisit for fields.
    Use the XmlDocument class to read the file. Then use an xpath expression
    in the SelectNodes method to select the nodes that you want.

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • rowe_newsgroups

      #3
      Re: basic XML reading question

      On Jul 31, 1:08 am, "Newbie" <new...@nospam. comwrote:
      Hi,
      >
      I am just starting to learn to use XML, so this is a really basic question.
      >
      I have managed to write my XML document to disk, and now want to read it
      back, and get the values from the XML file. My XML file is at the bottom.I
      am assuming that its correct (but I could be wrong)
      >
      What I want to be able to do is just get parts of the xml document, for
      example I only want to get the fields for the content type 'sample1' (the
      below sample has just one contenttype, normally it would have hundreds) I
      would also then want to get the choices for where they exisit for fields.
      >
      Whilst I am sure the answer is straight forward, I have not found an answer
      that i can understand easily.
      >
      Any tips would be great.
      >
      <?xml version="1.0"?>
      <!--Created on 7/30/2008 9:31:54 PM-->
      <libraries>
         <library id="97199410">
            <name>Service Documents</name>
            <ContentType>
               <name>Sample1 </name>
               <Field>
                  <name>Content Type</name>
                  <Choices>
                     <name>Documen t</name>
                  </Choices>
                  <Choices>
                     <name>Folder</name>
                  </Choices>
                  <Choices>
                     <name>Heath</name>
                  </Choices>
               </Field>
               <Field>
                  <name>Name</name>
               </Field>
               <Field>
                  <name>Title</name>
               </Field>
               <Field>
                  <name>Documen t Modified By</name>
               </Field>
               <Field>
                  <name>Documen t Created By</name>
               </Field>
               <Field>
                  <name>ABN</name>
               </Field>
               <Field>
                  <name>Legal Name</name>
               </Field>
               <Field>
                  <name>Option List</name>
                  <Choices>
                     <name>Selecti on 1</name>
                  </Choices>
                  <Choices>
                     <name>Selecti on 2</name>
                  </Choices>
                  <Choices>
                     <name>Selecti on 3</name>
                  </Choices>
                  <Choices>
                     <name>Selecti on 4</name>
                  </Choices>
               </Field>
               <Field>
                  <name>DropDow n Metadata Col</name>
                  <Choices>
                     <name>Choice1 </name>
                  </Choices>
                  <Choices>
                     <name>Choice2 </name>
                  </Choices>
                  <Choices>
                     <name>Choice3 </name>
                  </Choices>
               </Field>
            </ContentType>
         </library>
      </libraries>
      A good resource for you would be W3 School's articles on XPath
      expressions, that will give you the basic knowledge you need to use
      them as Goran has suggested.

      Sorry! We can't seem to find the resource you're looking for


      Thanks,

      Seth Rowe [MVP]

      Comment

      Working...