"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:On******** ******@TK2MSFTN GP09.phx.gbl...
Carl Lindmark wrote:
Just when I thought I had gotten the hang of it, another problem arose:
I can't seem to access the "xsi:type" attribute. That is, the XML file
looks
something like this:
...
<situation>
<objectID>123 </objectId>
<situationEleme nt xsi:type="td:ro adWorksType">
That attribute has a qualified name with the prefix xsi and the local name
type where the prefix xsi is usually bound to the namespace URI
http://www.w3.org/2001/XMLSchema-instance.
If you want to read that attribute value then you need to do
xmlElement.GetA ttribute("type" ,
"http://www.w3.org/2001/XMLSchema-instance")
If that does not help then show your code currently reading attributes so
that we can suggest how to improve it.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thank you very much for the reply, Martin!
If I've understood this correctly, though, the "GetAttribute() " solution is
something you use when you've created a new "XmlDocumen t" instance into
which you've read the XML file in question. Myself, however, I have read the
XML file into a DataSet (which I've been told to do).
If I had used the approach of reading the XML file into an XmlDocument in
the code and then stepped through the nodes, I could have used your
solution, or something like the following VB code, right?
tempNode = situation.Selec tSingleNode("td :situationEleme nt", nameSpcManager)
If Not IsNothing(tempN ode) Then xsiType(i) = tempNode.Attrib utes(0).Value
xsiType(i) = Replace(xsiType (i), "td:", "")
But, since I've been told to do my solution with DataSet, I don't know how
I should get the xsi:type attribute value. This is the code I currently
have, but trying to read the "xsi:type" value by doing
'childRow["xsi:type"]', as I have done in the following C# code, does not
work:
DataTable myTable = myDataSet.Table s["situation"]; // get the proper table
foreach (DataRow myRow in myTable.Rows)
{
string objectId = "" + myRow["objectId"];
foreach(DataRel ation myRelation in myRow.Table.Chi ldRelations)
{
DataRow[] childRows = myRow.GetChildR ows(myRelation) ;
foreach (DataRow childRow in childRows)
{
if (childRow.Table .TableName.Comp areTo("validity Period") == 0)
{
foreach (DataRow myRow2 in childRow.Table. Rows)
{
validityPeriodS tart = "" + myRow2["start"];
validityPeriodE nd = "" + myRow2["end"];
}
}
if (childRow.Table .TableName.Comp areTo("situatio nElement") == 0)
{
if (childRow["xsi:type"].ToString().Com pareTo("td:Road WorksType") ==
0)
{
foreach (DataRow myRow2 in childRow.Table. Rows)
{
elementObjectId = "" + myRow2["objectId"];
elementCodedDur ation = "" + myRow2["codedDurat ion"];
}
}
}
}
}
}
Sincerely,
Carl