basic XML reading question

N

Newbie

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>Document</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>Document Modified By</name>
</Field>
<Field>
<name>Document Created By</name>
</Field>
<Field>
<name>ABN</name>
</Field>
<Field>
<name>Legal Name</name>
</Field>
<Field>
<name>Option List</name>
<Choices>
<name>Selection 1</name>
</Choices>
<Choices>
<name>Selection 2</name>
</Choices>
<Choices>
<name>Selection 3</name>
</Choices>
<Choices>
<name>Selection 4</name>
</Choices>
</Field>
<Field>
<name>DropDown Metadata Col</name>
<Choices>
<name>Choice1</name>
</Choices>
<Choices>
<name>Choice2</name>
</Choices>
<Choices>
<name>Choice3</name>
</Choices>
</Field>
</ContentType>
</library>
</libraries>
 
G

Göran Andersson

Newbie said:
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.
 
R

rowe_newsgroups

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>Document</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>Document Modified By</name>
         </Field>
         <Field>
            <name>Document Created By</name>
         </Field>
         <Field>
            <name>ABN</name>
         </Field>
         <Field>
            <name>Legal Name</name>
         </Field>
         <Field>
            <name>Option List</name>
            <Choices>
               <name>Selection 1</name>
            </Choices>
            <Choices>
               <name>Selection 2</name>
            </Choices>
            <Choices>
               <name>Selection 3</name>
            </Choices>
            <Choices>
               <name>Selection 4</name>
            </Choices>
         </Field>
         <Field>
            <name>DropDown 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.

http://www.w3schools.com/XPath/default.asp

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top