Help with XML

J

Jole

Hi!

I'm using XML for the first time and I get stuck with that :(

I have XML file with next lines:

<Job Group="VS FAUFE" Name="100512677">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0405" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6" Part="Z62060B2231K310">
<Lots>
<Lot Name="100512677" Lotsize="31639" />
</Lots>
</Operation>
</Operations>
</Job>


And I dont know how to extract values 0,6 mm for Chip - Dickenklasse and
value BF 0405 for the Bauform...

I had try with examples that i found on internet but as I can see this XML
that i must parse is more complicated...

Can somebody help me with that?

Thanks

J.
 
A

Arne Vajhøj

I'm using XML for the first time and I get stuck with that :(

I have XML file with next lines:

<Job Group="VS FAUFE" Name="100512677">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0405" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6"
Part="Z62060B2231K310">
<Lots>
<Lot Name="100512677" Lotsize="31639" />
</Lots>
</Operation>
</Operations>
</Job>


And I dont know how to extract values 0,6 mm for Chip - Dickenklasse and
value BF 0405 for the Bauform...

I had try with examples that i found on internet but as I can see this XML
that i must parse is more complicated...

XmlDocument doc = new XmlDocument();
doc.Load(filename);
string val1 = doc.SelectSingleNode("//Job/Descriptor[@Group='Chip -
Dickenklasse']/@Name").Value;
string val3 =
doc.SelectSingleNode("//Job/Descriptor[@Group='Bauform']/@Name").Value;

Arne
 
J

Jole

XmlDocument doc = new XmlDocument();
doc.Load(filename);
string val1 = doc.SelectSingleNode("//Job/Descriptor[@Group='Chip - Dickenklasse']/@Name").Value;
string val3 = doc.SelectSingleNode("//Job/Descriptor[@Group='Bauform']/@Name").Value;

Arne

Thanks, but it throws exepction Object reference not set to an instance of an object.
 
J

Jeff Johnson

Jole said:
XmlDocument doc = new XmlDocument();
doc.Load(filename);
string val1 = doc.SelectSingleNode("//Job/Descriptor[@Group='Chip -
Dickenklasse']/@Name").Value;
string val3 =
doc.SelectSingleNode("//Job/Descriptor[@Group='Bauform']/@Name").Value;

Arne

Thanks, but it throws exepction Object reference not set to an instance
of an object.

You did declare a string variable called filename and set its value, right?
 
A

Arne Vajhøj

XmlDocument doc = new XmlDocument();
doc.Load(filename);
string val1 = doc.SelectSingleNode("//Job/Descriptor[@Group='Chip -
Dickenklasse']/@Name").Value;
string val3 =
doc.SelectSingleNode("//Job/Descriptor[@Group='Bauform']/@Name").Value;

Thanks, but it throws exepction Object reference not set to an instance
of an object.

What line?

And was the XML snippet you posted 100% accurate?

Arne
 
A

Arne Vajhøj

What line?

string val1 = doc.SelectSingleNode("//Job/Descriptor[@Group='Chip -
Dickenklasse']/@Name").Value;
And was the XML snippet you posted 100% accurate?

Yes, i made c/p form generated XML file

I forgot a level.

Try:

string val1 =
doc.SelectSingleNode("//Job/Descriptors/Descriptor[@Group='Chip -
Dickenklasse']/@Name").Value;

Arne
 
J

Jole

I forgot a level.

Try:

string val1 = doc.SelectSingleNode("//Job/Descriptors/Descriptor[@Group='Chip - Dickenklasse']/@Name").Value;

Arne

Yessss... That's it... Thank you very much...

But what if I had another same tag below that i paste here but with different values?

for example:

<Job Group="VS FAUFE" Name="100512677">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0405" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6" Part="Z62060B2231K310">
<Lots>
<Lot Name="100512677" Lotsize="31639" />
</Lots>
</Operation>
</Operations>
</Job>

<Job Group="VS FAUFE" Name="101036723">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0805" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6" Part="Z63060A2258K315">
<Lots>
<Lot Name="101036723" Lotsize="36928" />
</Lots>
</Operation>
</Operations>
</Job>


How to jump to the next...

Sorry for bother you, but I'm newbie :(
 
A

Arne Vajhøj

I forgot a level.

Try:

string val1 =
doc.SelectSingleNode("//Job/Descriptors/Descriptor[@Group='Chip -
Dickenklasse']/@Name").Value;

Yessss... That's it... Thank you very much...

But what if I had another same tag below that i paste here but with
different values?

for example:

<Job Group="VS FAUFE" Name="100512677">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0405" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6"
Part="Z62060B2231K310">
<Lots>
<Lot Name="100512677" Lotsize="31639" />
</Lots>
</Operation>
</Operations>
</Job>

<Job Group="VS FAUFE" Name="101036723">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0805" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6"
Part="Z63060A2258K315">
<Lots>
<Lot Name="101036723" Lotsize="36928" />
</Lots>
</Operation>
</Operations>
</Job>


How to jump to the next...

Besides .SelectSingleNode er der også en SelectNodes!

Something like:

foreach(XmlNode n in
doc.SelectNodes("//Job/Descriptors/Descriptor[@Group='Chip -
Dickenklasse']"))
{
string val1 = n.SelectSingleNode("@Name").Value;
// whatever
}

Arne
 
J

Jole

Besides .SelectSingleNode er der også en SelectNodes!

Something like:

foreach(XmlNode n in doc.SelectNodes("//Job/Descriptors/Descriptor[@Group='Chip - Dickenklasse']"))
{
string val1 = n.SelectSingleNode("@Name").Value;
// whatever
}

Arne

Thank you very much, that works fine...
But what if I want to get this value by some searching criteria...

For example if i have this:


<Job Group="VS FAUFE" Name="100512677">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0405" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6" Part="Z62060B2231K310">
<Lots>
<Lot Name="100512677" Lotsize="31639" />
</Lots>
</Operation>
</Operations>
</Job>


Now, I wan't to get value of Chip - Disckenklasse by Job Group that has value
100512677 or any other that is written in my XML file. Is it possible that?
I think that parsing XML is not very easy as it looks.. :/
 
A

Arne Vajhøj

Besides .SelectSingleNode er der også en SelectNodes!

Something like:

foreach(XmlNode n in
doc.SelectNodes("//Job/Descriptors/Descriptor[@Group='Chip -
Dickenklasse']"))
{
string val1 = n.SelectSingleNode("@Name").Value;
// whatever
}

Thank you very much, that works fine...
But what if I want to get this value by some searching criteria...

For example if i have this:

<Job Group="VS FAUFE" Name="100512677">
<Descriptors>
<Descriptor Group="Chip - Dickenklasse" Name="0,6 mm" />
<Descriptor Group="Bauform" Name="BF 0405" />
</Descriptors>
<Operations>
<Operation Name="DISPO" Number="6" PartGroup="KBVS D6"
Part="Z62060B2231K310">
<Lots>
<Lot Name="100512677" Lotsize="31639" />
</Lots>
</Operation>
</Operations>
</Job>


Now, I wan't to get value of Chip - Disckenklasse by Job Group that has
value
100512677 or any other that is written in my XML file. Is it possible that?
Yes.

http://www.google.com/#hl=en&q=xpath+tutorial

I think that parsing XML is not very easy as it looks.. :/

I can not really think of any format and query language easier
than XML and XSLT for this.

Arne
 

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