473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

extract the blue color

Hi guys

I don't understand what I am doing wrong

I wrote this code, in order to manipulate some Xml data, I have problem with
level 4 (properties section):

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

XmlDocument xmlDoc = new XmlDocument();
XmlNodeList items = xmlDoc.GetElementsByTagName("item");
IEnumerator iEnum = items.GetEnumerator();

while(iEnum.MoveNext())
{
XmlNode itemNode = iEnum.Current ;
XmlElement name = itemNode.SelectSingleNode("name");
XmlNodeList properties =
itemNode.SelectNodes("Properties");
for(int i=0;i<properties.Count;i++)
MessageBox.Show(properties[i]);
}

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

for extracting some data on this XML file :

//XML -----------------------------------------------------------------------------------------------------------------------------------------

<items>

<item type="car">

<name ="Volvo">

<Properties>

<manufacturer="F16" />

<engine="1300" />

<color="White"/>

</properties>

</item>

</items>

//XML -----------------------------------------------------------------------------------------------------------------------------------------

The problem is that I'm getting from the for loop message : "F161300White"

Instead of 3 message boxes: "F16" "1300" "White"

please advise .

Thank you

Sharon


Nov 17 '05 #1
4 1843
Hi Sharon,
you will need to restructure your XML, you have things like:

<engine="1300" />

this is not right, you need to either put the text inside the element i.e.
<engine>1300</engine> or put the value as an attribute value inside the
element:

<engine capacity="1300" />
Then when you loop through the properties nodes you will either say:

properties[i].InnerText
when using <engine>1300</engine>

or you will say properties[i].Attributes["capacity"].Value
when using <engine capacity="1300" />
Hope that helps
Mark R Dawson
http://www.markdawson.org


"Sharon" wrote:
Hi guys

I don't understand what I am doing wrong

I wrote this code, in order to manipulate some Xml data, I have problem with
level 4 (properties section):

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

XmlDocument xmlDoc = new XmlDocument();
XmlNodeList items = xmlDoc.GetElementsByTagName("item");
IEnumerator iEnum = items.GetEnumerator();

while(iEnum.MoveNext())
{
XmlNode itemNode = iEnum.Current ;
XmlElement name = itemNode.SelectSingleNode("name");
XmlNodeList properties =
itemNode.SelectNodes("Properties");
for(int i=0;i<properties.Count;i++)
MessageBox.Show(properties[i]);
}

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

for extracting some data on this XML file :

//XML -----------------------------------------------------------------------------------------------------------------------------------------

<items>

<item type="car">

<name ="Volvo">

<Properties>

<manufacturer="F16" />

<engine="1300" />

<color="White"/>

</properties>

</item>

</items>

//XML -----------------------------------------------------------------------------------------------------------------------------------------

The problem is that I'm getting from the for loop message : "F161300White"

Instead of 3 message boxes: "F16" "1300" "White"

please advise .

Thank you

Sharon


Nov 17 '05 #2
Thank you Mark

Sorry for wrong posting the XML file
the xml go's its like this :

//XML -----------------------------------------------------------------------------------------------------------------------------------------

<items>

<item type="car">

<name>Volvo</name>

<Properties>

<manufacturer>F16 </manufacturer>

<engine>1300</engine>

<color>White</color>

</properties>

</item>

</items>

//XML -----------------------------------------------------------------------------------------------------------------------------------------


"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com... Hi Sharon,
you will need to restructure your XML, you have things like:

<engine="1300" />

this is not right, you need to either put the text inside the element i.e.
<engine>1300</engine> or put the value as an attribute value inside the
element:

<engine capacity="1300" />
Then when you loop through the properties nodes you will either say:

properties[i].InnerText
when using <engine>1300</engine>

or you will say properties[i].Attributes["capacity"].Value
when using <engine capacity="1300" />
Hope that helps
Mark R Dawson
http://www.markdawson.org


"Sharon" wrote:
Hi guys

I don't understand what I am doing wrong

I wrote this code, in order to manipulate some Xml data, I have problem
with
level 4 (properties section):

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

XmlDocument xmlDoc = new XmlDocument();
XmlNodeList items = xmlDoc.GetElementsByTagName("item");
IEnumerator iEnum = items.GetEnumerator();

while(iEnum.MoveNext())
{
XmlNode itemNode = iEnum.Current ;
XmlElement name = itemNode.SelectSingleNode("name");
XmlNodeList properties =
itemNode.SelectNodes("Properties");
for(int i=0;i<properties.Count;i++)
MessageBox.Show(properties[i]);
}

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

for extracting some data on this XML file :

//XML -----------------------------------------------------------------------------------------------------------------------------------------

<items>

<item type="car">

<name ="Volvo">

<Properties>

<manufacturer="F16" />

<engine="1300" />

<color="White"/>

</properties>

</item>

</items>

//XML -----------------------------------------------------------------------------------------------------------------------------------------

The problem is that I'm getting from the for loop message :
"F161300White"

Instead of 3 message boxes: "F16" "1300" "White"

please advise .

Thank you

Sharon


Nov 17 '05 #3
Hi Sharon,
I was not able to reproduce the issue you were seeing with the code you
submitted, I suspect that is not the exact code you are really running.
However I modified it to make it work, maybe this will help:

using System;
using System.Collections;
using System.Xml;

namespace ConsoleApplication10
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string xml = @"<items>
<item type=""car"">
<name>Volvo</name>
<properties>
<manufacturer>F16</manufacturer>
<engine>1300</engine>
<color>White</color>
</properties>
</item>
</items>";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);

XmlNodeList items = xmlDoc.GetElementsByTagName("item");
IEnumerator iEnum = items.GetEnumerator();

while(iEnum.MoveNext())
{
XmlNode itemNode = (XmlNode)iEnum.Current ;
XmlNode name = itemNode.SelectSingleNode("name");
XmlNodeList properties = itemNode.SelectNodes("properties");
for(int i=0;i<properties.Count;i++)
{
XmlNode propertyItem = properties[i].FirstChild;
while(propertyItem != null)
{
Console.WriteLine(propertyItem.InnerText);
propertyItem = propertyItem.NextSibling;
}

}
}

Console.ReadLine();
}
}
}

"Sharon" wrote:
Thank you Mark

Sorry for wrong posting the XML file
the xml go's its like this :

//XML -----------------------------------------------------------------------------------------------------------------------------------------

<items>

<item type="car">

<name>Volvo</name>

<Properties>

<manufacturer>F16 </manufacturer>

<engine>1300</engine>

<color>White</color>

</properties>

</item>

</items>

//XML -----------------------------------------------------------------------------------------------------------------------------------------

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
Hi Sharon,
you will need to restructure your XML, you have things like:

<engine="1300" />

this is not right, you need to either put the text inside the element i.e.
<engine>1300</engine> or put the value as an attribute value inside the
element:

<engine capacity="1300" />
Then when you loop through the properties nodes you will either say:

properties[i].InnerText
when using <engine>1300</engine>

or you will say properties[i].Attributes["capacity"].Value
when using <engine capacity="1300" />
Hope that helps
Mark R Dawson
http://www.markdawson.org


"Sharon" wrote:
Hi guys

I don't understand what I am doing wrong

I wrote this code, in order to manipulate some Xml data, I have problem
with
level 4 (properties section):

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

XmlDocument xmlDoc = new XmlDocument();
XmlNodeList items = xmlDoc.GetElementsByTagName("item");
IEnumerator iEnum = items.GetEnumerator();

while(iEnum.MoveNext())
{
XmlNode itemNode = iEnum.Current ;
XmlElement name = itemNode.SelectSingleNode("name");
XmlNodeList properties =
itemNode.SelectNodes("Properties");
for(int i=0;i<properties.Count;i++)
MessageBox.Show(properties[i]);
}

//CODE -----------------------------------------------------------------------------------------------------------------------------------------

for extracting some data on this XML file :

//XML -----------------------------------------------------------------------------------------------------------------------------------------

<items>

<item type="car">

<name ="Volvo">

<Properties>

<manufacturer="F16" />

<engine="1300" />

<color="White"/>

</properties>

</item>

</items>

//XML -----------------------------------------------------------------------------------------------------------------------------------------

The problem is that I'm getting from the for loop message :
"F161300White"

Instead of 3 message boxes: "F16" "1300" "White"

please advise .

Thank you

Sharon



Nov 17 '05 #4
Thank you Mark

This code works excellent,

I reinstalled the .Net framework (sp1 for 1.1), maybe something with the
framework was wrong ?

Because now, the previous code is working too ,

wired ...

Sharon


"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
Hi Sharon,
I was not able to reproduce the issue you were seeing with the code you
submitted, I suspect that is not the exact code you are really running.
However I modified it to make it work, maybe this will help:

using System;
using System.Collections;
using System.Xml;

namespace ConsoleApplication10
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string xml = @"<items>
<item type=""car"">
<name>Volvo</name>
<properties>
<manufacturer>F16</manufacturer>
<engine>1300</engine>
<color>White</color>
</properties>
</item>
</items>";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);

XmlNodeList items = xmlDoc.GetElementsByTagName("item");
IEnumerator iEnum = items.GetEnumerator();

while(iEnum.MoveNext())
{
XmlNode itemNode = (XmlNode)iEnum.Current ;
XmlNode name = itemNode.SelectSingleNode("name");
XmlNodeList properties = itemNode.SelectNodes("properties");
for(int i=0;i<properties.Count;i++)
{
XmlNode propertyItem = properties[i].FirstChild;
while(propertyItem != null)
{
Console.WriteLine(propertyItem.InnerText);
propertyItem = propertyItem.NextSibling;
}

}
}

Console.ReadLine();
}
}
}

"Sharon" wrote:
Thank you Mark

Sorry for wrong posting the XML file
the xml go's its like this :

>> //XML -----------------------------------------------------------------------------------------------------------------------------------------
>>
>> <items>
>>
>> <item type="car">
>>
>> <name>Volvo</name>
>>
>> <Properties>
>>
>> <manufacturer>F16 </manufacturer>
>>
>> <engine>1300</engine>
>>
>> <color>White</color>
>>
>> </properties>
>>
>> </item>
>>
>> </items>
>>
>> //XML -----------------------------------------------------------------------------------------------------------------------------------------
>>

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
> Hi Sharon,
> you will need to restructure your XML, you have things like:
>
> <engine="1300" />
>
> this is not right, you need to either put the text inside the element
> i.e.
> <engine>1300</engine> or put the value as an attribute value inside the
> element:
>
> <engine capacity="1300" />
>
>
> Then when you loop through the properties nodes you will either say:
>
> properties[i].InnerText
> when using <engine>1300</engine>
>
> or you will say properties[i].Attributes["capacity"].Value
> when using <engine capacity="1300" />
>
>
> Hope that helps
> Mark R Dawson
> http://www.markdawson.org
>
>
>
>
>
>
> "Sharon" wrote:
>
>> Hi guys
>>
>> I don't understand what I am doing wrong
>>
>> I wrote this code, in order to manipulate some Xml data, I have
>> problem
>> with
>> level 4 (properties section):
>>
>>
>>
>> //CODE -----------------------------------------------------------------------------------------------------------------------------------------
>>
>> XmlDocument xmlDoc = new XmlDocument();
>> XmlNodeList items = xmlDoc.GetElementsByTagName("item");
>> IEnumerator iEnum = items.GetEnumerator();
>>
>> while(iEnum.MoveNext())
>> {
>> XmlNode itemNode = iEnum.Current ;
>> XmlElement name =
>> itemNode.SelectSingleNode("name");
>> XmlNodeList properties =
>> itemNode.SelectNodes("Properties");
>> for(int i=0;i<properties.Count;i++)
>> MessageBox.Show(properties[i]);
>> }
>>
>> //CODE -----------------------------------------------------------------------------------------------------------------------------------------
>>
>> for extracting some data on this XML file :
>>
>>
>>
>> //XML -----------------------------------------------------------------------------------------------------------------------------------------
>>
>> <items>
>>
>> <item type="car">
>>
>> <name ="Volvo">
>>
>> <Properties>
>>
>> <manufacturer="F16" />
>>
>> <engine="1300" />
>>
>> <color="White"/>
>>
>> </properties>
>>
>> </item>
>>
>> </items>
>>
>> //XML -----------------------------------------------------------------------------------------------------------------------------------------
>>
>>
>>
>> The problem is that I'm getting from the for loop message :
>> "F161300White"
>>
>> Instead of 3 message boxes: "F16" "1300" "White"
>>
>>
>>
>> please advise .
>>
>> Thank you
>>
>> Sharon
>>
>>
>>
>>
>>


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Don Crossman | last post by:
Assume a MYSQL table, foo. One column, bar datetime. Two rows: 2004-01-01 08:00:00 2004-02-01 08:00:00 select * from foo where extract(day from bar)=1; 2 rows in set...
3
by: Phong Ho | last post by:
Hi everyone, I try to write a simple web crawler. It has to do the following: 1) Open an URL and retrieve a HTML file. 2) Extract news headlines from the HTML file 3) Put the headlines into a...
7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
9
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and...
10
by: Robert Schultz | last post by:
I have a C/C++ file that I simply want to 'extract' a function from. Something like: extract <function name> <c or cpp file> I want it to return from the beginning of the function, to the end. ...
1
by: Scott Andrew | last post by:
I have my app extracting thumbnails nicely for video and images. I have noticed however that for video there are 5 threads added everytime I call extract. And those threads never go away. Also the...
3
by: jarod1701 | last post by:
Hi, I'm currently trying to create a regular expression that can extract certain elements from a url. The url will be of the following form: http://user:pass@www.sitename.com I want a...
1
by: csgraham74 | last post by:
Hi Guys, I want to populate a nodelist so that i can extract various details. The xml document i have is similar to the one below. baiscally i want to extract the first instance of <PP>...
7
by: teo | last post by:
hallo, I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document. Like the description that Google returns when it has found a...
3
bilibytes
by: bilibytes | last post by:
Hi everyone, I am wondering if it is possible to extract the key values of an array into object variables. lets say i have the following $_REQUEST array: $var_array = array("color" =>...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.