473,221 Members | 2,077 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,221 software developers and data experts.

Reading the value of an "xsi:type" attribute [unfortunate, but necessary cross-posting]

*Cross-posting from microsoft.public.dotnet.languages.csharp, since I
believe the question is better suited in this XML group*

Hello all,

I'm having some problems understanding all the ins and outs with datasets
and datatables (and navigating through the filled datatable)...

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>
<situationElement xsi:type="td:roadWorksType">
...
</situationElement>
</situation>

But when I try and filter the contents of the file (after I've read all
"situation" tags into a datatable) I can't seem to access the attribute
"xsi:type" - which I need to do to distinguish between different types.

When I change the XML and write "xsi_type" instead of "xsi:type", I'm able
to access this attribute by going to the right row and write
'rowname["xsi_type"]', but the files I will have to work on use the
attribute "xsi:type" and I haven't been able to access that attribute. Can
anyone help me read the value of the xsi:type attribute? Any pointers?
Thanks in advance!

Sincerely,
Carl
Nov 12 '05 #1
3 9278


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>
<situationElement xsi:type="td:roadWorksType">


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.GetAttribute("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/
Nov 12 '05 #2

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:On**************@TK2MSFTNGP09.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>
<situationElement xsi:type="td:roadWorksType">


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.GetAttribute("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 "XmlDocument" 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.SelectSingleNode("td:situationElement", nameSpcManager)
If Not IsNothing(tempNode) Then xsiType(i) = tempNode.Attributes(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.Tables["situation"]; // get the proper table
foreach (DataRow myRow in myTable.Rows)
{
string objectId = "" + myRow["objectId"];
foreach(DataRelation myRelation in myRow.Table.ChildRelations)
{
DataRow[] childRows = myRow.GetChildRows(myRelation);
foreach (DataRow childRow in childRows)
{
if (childRow.Table.TableName.CompareTo("validityPerio d") == 0)
{
foreach (DataRow myRow2 in childRow.Table.Rows)
{
validityPeriodStart = "" + myRow2["start"];
validityPeriodEnd = "" + myRow2["end"];
}
}
if (childRow.Table.TableName.CompareTo("situationElem ent") == 0)
{
if (childRow["xsi:type"].ToString().CompareTo("td:RoadWorksType") ==
0)
{
foreach (DataRow myRow2 in childRow.Table.Rows)
{
elementObjectId = "" + myRow2["objectId"];
elementCodedDuration = "" + myRow2["codedDuration"];
}
}
}
}
}
}
Sincerely,
Carl
Nov 12 '05 #3

"Carl Lindmark" <RepliesInNewsGroupOnly@Thanks> skrev i meddelandet
news:eS**************@TK2MSFTNGP09.phx.gbl...

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:On**************@TK2MSFTNGP09.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>
<situationElement xsi:type="td:roadWorksType">
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.GetAttribute("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 "XmlDocument" 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.SelectSingleNode("td:situationElement", nameSpcManager) If Not IsNothing(tempNode) Then xsiType(i) = tempNode.Attributes(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.Tables["situation"]; // get the proper table foreach (DataRow myRow in myTable.Rows)
{
string objectId = "" + myRow["objectId"];
foreach(DataRelation myRelation in myRow.Table.ChildRelations)
{
DataRow[] childRows = myRow.GetChildRows(myRelation);
foreach (DataRow childRow in childRows)
{
if (childRow.Table.TableName.CompareTo("validityPerio d") == 0)
{
foreach (DataRow myRow2 in childRow.Table.Rows)
{
validityPeriodStart = "" + myRow2["start"];
validityPeriodEnd = "" + myRow2["end"];
}
}
if (childRow.Table.TableName.CompareTo("situationElem ent") == 0)
{
if (childRow["xsi:type"].ToString().CompareTo("td:RoadWorksType") == 0)
{
foreach (DataRow myRow2 in childRow.Table.Rows)
{
elementObjectId = "" + myRow2["objectId"];
elementCodedDuration = "" + myRow2["codedDuration"];
}
}
}
}
}
}
Sincerely,
Carl


I know the code looks a bit complicated (and maybe not totally correct?),
but I'm not COMPLETELY off the mark, now am I? One IS supposed to be able
to work with datasets & tables this way, isn't one? And shouldn't one also
be able to read the value of attributes as I described?

Any input would be greatly appreciated!
/Carl
Nov 12 '05 #4

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

Similar topics

8
by: johnsocs | last post by:
How do you validate the following XML document, I'm having problems with element 'one' with the attribute xsi:type="xsd:string" <?xml version="1.0" encoding="UTF-8"?> <zero...
2
by: Jason Cartwright | last post by:
I have an abstract base class and two derived classes that I want to serialize and deserialize with schema validation. When I serialize instances of the derived classes the XmlSerializer adds the...
0
by: Carl Lindmark | last post by:
Hello all, I'm having some problems understanding all the ins and outs with datasets and datatables (and navigating through the filled datatable)... Just when I thought I had gotten the hang...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the...
0
by: Kaimar Seljamäe | last post by:
Hi, I have to create a web service client which uses SOAP encoding but does not use "multi-reference" values (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513 item 10). If I...
6
by: geoffrobinson | last post by:
Hi, I'm serializing an object using XmlSerializer. It is serializing, but we are getting errors upon deserialization. We use the following code to serialize: FileStream fs = new...
1
by: Ganesh Muthuvelu | last post by:
Hello, Is it possible to make the dataset give the "xsi:type" data as well?. I need result from the dataset.GetXML method something like this for the column "a": <a xsi:type="int">12</a> Is...
1
by: tankbattle | last post by:
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element...
0
by: lamagra | last post by:
Hello all, I first wanted to say that this is my first post and thank you for taking a look at it. My question: I am trying to write an XML Parser using the Lib:XML package. The problem that...
2
by: motorpage | last post by:
Hi, I am a newbie to schema definitions so forgive me if this is a simple question. I am trying to create a schema for a complex type that allows instances of either of the two forms: ...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.