Page 1 of 1
XML C# Question...
Posted: Wed Aug 13, 2008 2:57 pm
by Turbanator
Wondering if anyone can help me on this one.
I have an XML file in the following format:
Code: Select all
<product>
<tier1>
<id>1</id>
</tier1>
<tier2>
<relation>2</relation>
<tier2>
</product>
<product>
<tier1>
<id>2</id>
</tier1>
</product>
This is being pulled into a dataset using Dataset.ReadXml. The resulting XML has 3 tables, product (empty rows), tier1 (just ids), tier2 (just relations).
To read out all the id's i can simply reference to them using:
myDS.Tables["tier1"].Rows
[0].ToString();
To get all the relations, similarly I can use myDS.Tables["tier2"].Rows[0].ToString();
How do I get 2 figures out of this, the relation and it's corresponding id, so the output for the above example would be:
ID: 1 Relation: 2
ID: 2 Relation: Null
?
Re: XML C# Question...
Posted: Wed Aug 13, 2008 3:06 pm
by Doombrain
i suggest you find the answer.
Re: XML C# Question...
Posted: Wed Aug 13, 2008 3:12 pm
by sirstrongbad
Turbanator wrote:Wondering if anyone can help me on this one.
I have an XML file in the following format:
Code: Select all
<product>
<tier1>
<id>1</id>
</tier1>
<tier2>
<relation>2</relation>
<tier2>
</product>
<product>
<tier1>
<id>2</id>
</tier1>
</product>
This is being pulled into a dataset using Dataset.ReadXml. The resulting XML has 3 tables, product (empty rows), tier1 (just ids), tier2 (just relations).
To read out all the id's i can simply reference to them using:
myDS.Tables["tier1"].Rows
[0].ToString();
To get all the relations, similarly I can use myDS.Tables["tier2"].Rows[0].ToString();
How do I get 2 figures out of this, the relation and it's corresponding id, so the output for the above example would be:
ID: 1 Relation: 2
ID: 2 Relation: Null
?
Not sure I'm understanding what your XML is trying to do, but I would go in this direction... (not accurate by any means, but might give you an idea)
Code: Select all
Dim i as Int32
Dim j as Int32
Dim _innerRow as DataRow
dim _id as String
dim _relation as String
For i = 0 to myDs.Rows.Count - 1
_innerRow = myDs.Rows(i)
for j = 0 to _innerRow.Rows.Count - 1
_id = _innerRow.Rows(j)(0).ToString
_relation = iif(_innerRow.Rows(j)(1).ToString = String.Empty, DbNull.Value, _innerRow.Rows(j)(1).ToString))
next
Next
Re: XML C# Question...
Posted: Wed Aug 13, 2008 4:25 pm
by MKJ
i suggest you post this in T&T. cunt
Re: XML C# Question...
Posted: Wed Aug 13, 2008 4:44 pm
by inolen
What's the purpose of the tier1/tier2 tags?
Edit: Feel free to IM me, I'm not doing much atm

Re: XML C# Question...
Posted: Wed Aug 13, 2008 4:52 pm
by Turbanator
this is a data file that holds information i need to visualize, so i'm reverse engineering it. I've got it back to an XML form, and now I need to load data off the XML into a new dataset so I can output a "clean xml" to work with for visualization.
Here is a real world example of the data I'm working with:
Code: Select all
<LI>
<BASICS>
<LI_KEY>1140</LI_KEY>
<LABEL>Allowed CAB to meet target coverage</LABEL>
</BASICS>
<T_DATA>
<F_TOKENS>
<F_TK>
<TK_T>5</TK_T>
<TK_TX>IF</TK_TX>
<TK_EX_T>1</TK_EX_T>
</F_TK>
<F_TK>
<TK_T>4</TK_T>
<TK_LI_ID>1132</TK_LI_ID>
<TK_EX_T>0</TK_EX_T>
</F_TK>
<F_TK>
<TK_T>8</TK_T>
<TK_TX>/</TK_TX>
<TK_EX_T>6</TK_EX_T>
</F_TK>
<F_TK>
<TK_T>4</TK_T>
<TK_LI_ID>62</TK_LI_ID>
<TK_EX_T>0</TK_EX_T>
<TK_ANC>T</TK_ANC>
</F_TK>
</F_TOKENS>
</T_DATA>
</LI>
I can pull out all the LI->BASICS->LI_KEY and LABEL values quite easily, they're in the same "basics" table in the dataset... i need to pull out all the TK_LI_ID values and their corresponding LI_KEY values, but these values are stored in two different tables bound together by the same LI parent. So in this above example my first clean data table would read:
1140, "Allowed CAB to meet target coverage"
and my 2nd data table would read:
1140, 1132
1140, 62
Re: XML C# Question...
Posted: Wed Aug 13, 2008 4:56 pm
by Turbanator
The code for pulling out LI_KEY and LABEL:
Code: Select all
for (int i = 0; i <= myDS.Tables["Basics"].Rows.Count -1 ; i++)
{
dt1.Rows.Add(new object[] { myDS.Tables["Basics"].Rows[i][0].ToString(), myDS.Tables["Basics"].Rows[i][1].ToString() });
}
Re: XML C# Question...
Posted: Wed Aug 13, 2008 5:09 pm
by sirstrongbad
Turbanator wrote:this is a data file that holds information i need to visualize, so i'm reverse engineering it. I've got it back to an XML form, and now I need to load data off the XML into a new dataset so I can output a "clean xml" to work with for visualization.
Here is a real world example of the data I'm working with:
Code: Select all
<LI>
<BASICS>
<LI_KEY>1140</LI_KEY>
<LABEL>Allowed CAB to meet target coverage</LABEL>
</BASICS>
<T_DATA>
<F_TOKENS>
<F_TK>
<TK_T>5</TK_T>
<TK_TX>IF</TK_TX>
<TK_EX_T>1</TK_EX_T>
</F_TK>
<F_TK>
<TK_T>4</TK_T>
<TK_LI_ID>1132</TK_LI_ID>
<TK_EX_T>0</TK_EX_T>
</F_TK>
<F_TK>
<TK_T>8</TK_T>
<TK_TX>/</TK_TX>
<TK_EX_T>6</TK_EX_T>
</F_TK>
<F_TK>
<TK_T>4</TK_T>
<TK_LI_ID>62</TK_LI_ID>
<TK_EX_T>0</TK_EX_T>
<TK_ANC>T</TK_ANC>
</F_TK>
</F_TOKENS>
</T_DATA>
</LI>
I can pull out all the LI->BASICS->LI_KEY and LABEL values quite easily, they're in the same "basics" table in the dataset... i need to pull out all the TK_LI_ID values and their corresponding LI_KEY values, but these values are stored in two different tables bound together by the same LI parent. So in this above example my first clean data table would read:
1140, "Allowed CAB to meet target coverage"
and my 2nd data table would read:
1140, 1132
1140, 62
The XML looks malformed to me... The children of F_TOKENS are all screwy. Considering those children have different keys, what happens when one of the children is not present? Defaults to null? Seems like it would make your life much easier parsing this data if the children at least matched (with no values if none are present).
Re: XML C# Question...
Posted: Wed Aug 13, 2008 5:18 pm
by Turbanator
the app that builds this data (from which i pull out this XML file from), was developed in 2003... screwy is an understatement, the whole thing is fucked but it is what it is... and I need to get these relationship links out of it :\
to answer your question, the dataset reads them as blank when they're not present... so a simple check of "if ....length > 1 ... then add the item to new dt" would get rid of all the dodgy crap.
Re: XML C# Question...
Posted: Wed Aug 13, 2008 5:21 pm
by Turbanator
inolen wrote:Edit: Feel free to IM me, I'm not doing much atm

i can't remember my icq password... lol
is my e-mail address on my icq account set to raj [at] turbanator [dot] net ?
Re: XML C# Question...
Posted: Wed Aug 13, 2008 6:43 pm
by PhoeniX
Turbanator wrote:inolen wrote:Edit: Feel free to IM me, I'm not doing much atm

i can't remember my icq password... lol
is my e-mail address on my icq account set to raj [at] turbanator [dot] net ?
Your account isn't showing an address.. maybe it was set as hidden?
Re: XML C# Question...
Posted: Wed Aug 13, 2008 6:43 pm
by ^misantropia^
Turbanator wrote:and now I need to load data off the XML into a new dataset so I can output a "clean xml" to work with for visualization.
This is the kind of work XSLT was invented for.
Re: XML C# Question...
Posted: Wed Aug 13, 2008 6:51 pm
by inolen
^misantropia^ wrote:Turbanator wrote:and now I need to load data off the XML into a new dataset so I can output a "clean xml" to work with for visualization.
This is the kind of work XSLT was invented for.
Yea, but then you have the overhead of learning the syntax for that

Re: XML C# Question...
Posted: Thu Aug 14, 2008 8:49 am
by MKJ
xslt is easier than c#, innit
Re: XML C# Question...
Posted: Thu Aug 14, 2008 12:24 pm
by Turbanator
meh... achieved it using XPath... dataset just wasn't working. XPath is slick i have to say.