473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

*Cross-posting from microsoft.publi c.dotnet.langua ges.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>
<situationEleme nt xsi:type="td:ro adWorksType">
...
</situationElemen t>
</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 9387


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/
Nov 12 '05 #2

"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
Nov 12 '05 #3

"Carl Lindmark" <RepliesInNewsG roupOnly@Thanks > skrev i meddelandet
news:eS******** ******@TK2MSFTN GP09.phx.gbl...

"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


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
3483
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <one xsi:type="xsd:string">test</one> </zero>
2
3301
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 xsi:type="DerivedClass" attribute and the Instance Namespace. When I attempt to validate the xml upon deserialization the XmlValidatingReader chokes on this attribute value. I can't seem to find a way around this. Any suggestions?
0
2215
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 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>
7
5404
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 filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
0
1942
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 create SOAP client like this: public class StockService : SoapHttpClientProtocol {
6
10809
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 FileStream(NavCmdFile, FileMode.Create, FileAccess.Write, FileShare.None); XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
1
1775
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 it possible?. I would appreciate any pointers/code help. Thanks.
1
4745
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 name="city" type="string"/> </sequence> </complexType> and <complexType name="Address" block="restriction">
0
1607
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 I am having is that I seem to not be able to parse the a "local name" searching for an xsi:type="test". Here is an example of what I am looking for.
2
1830
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: <test1 state=true> <name>test1/>
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.