Connecting Tech Pros Worldwide Forums | Help | Site Map

basic XML reading question

Newbie
Guest
 
Posts: n/a
#1: Jul 31 '08
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>


=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
 
Posts: n/a
#2: Jul 31 '08

re: basic XML reading question


Newbie wrote:
Quote:
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
_____
http://www.guffa.com
rowe_newsgroups
Guest
 
Posts: n/a
#3: Jul 31 '08

re: basic XML reading question


On Jul 31, 1:08*am, "Newbie" <new...@nospam.comwrote:
Quote:
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/
Closed Thread