Namespaces and ReadXML

Hi everyone,

I'm a real newbie, so please be patient :-)

I am loading an XML files into a datagrid. It works fine. To further process 
the information, I need to identify the column type. This information is 
basically in the namespace: x-ALS means it's a picklist type and x-txt a 
non-picklist.

<?xml version='1.0' ?>
<tmx xmlns:x-TXT="http://www.x-txt.org" xmlns:x-ALS="http://www.x-als.org">
<tu>
    <x-ALS:Status>Approved</x-ALS:Status>
    <x-ALS:Department>Marketing</x-ALS:Department>
    <x-ALS:DocType>Internet</x-ALS:DocType>
    <x-TXT:DocName>Update</x-TXT:DocName>
</tu>
.......

When I load the XML the datagrid columns are called Status, Department, etc. 
And not x-ALS:Status as I initially expected. If this information was not 
stripped from the column name it would help me identify the column type. Do 
I need to preprocess the XML file to transfer this information to the column 
title? i.e.
.....
<tu>
    <x-ALS:ALS_Status>Approved</x-ALS:Status>
    <x-ALS:ALS_Department>Marketing</x-ALS:Department>
    <x-ALS:ALS_DocType>Internet</x-ALS:DocType>
    <x-TXT:ALS_DocName>Update</x-TXT:DocName>
</tu>
....

Or is there a more elegant way of retrieving this information?

Has anyone got any ideas?

Best regards,

Robert 


0
7/5/2007 9:32:00 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
751 Views

Similar Articles

[PageSpeed] 2

"Robert Bevington" <rbevington@freenet.de> wrote in message 
news:%23Tqcsv0vHHA.4592@TK2MSFTNGP05.phx.gbl...
> Hi everyone,
>
> I'm a real newbie, so please be patient :-)
>
> I am loading an XML files into a datagrid. It works fine. To further 
> process the information, I need to identify the column type. This 
> information is basically in the namespace: x-ALS means it's a picklist 
> type and x-txt a non-picklist.
>
> <?xml version='1.0' ?>
> <tmx xmlns:x-TXT="http://www.x-txt.org" 
> xmlns:x-ALS="http://www.x-als.org">
> <tu>
>    <x-ALS:Status>Approved</x-ALS:Status>
>    <x-ALS:Department>Marketing</x-ALS:Department>
>    <x-ALS:DocType>Internet</x-ALS:DocType>
>    <x-TXT:DocName>Update</x-TXT:DocName>
> </tu>
> ......
>
> When I load the XML the datagrid columns are called Status, Department, 
> etc. And not x-ALS:Status as I initially expected. If this information was 
> not stripped from the column name it would help me identify the column 
> type. Do I need to preprocess the XML file to transfer this information to 
> the column title? i.e.
> ....
> <tu>
>    <x-ALS:ALS_Status>Approved</x-ALS:Status>
>    <x-ALS:ALS_Department>Marketing</x-ALS:Department>
>    <x-ALS:ALS_DocType>Internet</x-ALS:DocType>
>    <x-TXT:ALS_DocName>Update</x-TXT:DocName>
> </tu>

That's a strange way of indicating data type, but check the 
DataColumn.Namespace property after you load.
-- 
John Saunders [MVP]

0
John
7/6/2007 12:09:36 AM
John Saunders [MVP] schrieb:
> "Robert Bevington" <rbevington@freenet.de> wrote in message 
> news:%23Tqcsv0vHHA.4592@TK2MSFTNGP05.phx.gbl...
>> Hi everyone,
>>
>> I'm a real newbie, so please be patient :-)
>>
>> I am loading an XML files into a datagrid. It works fine. To further 
>> process the information, I need to identify the column type. This 
>> information is basically in the namespace: x-ALS means it's a picklist 
>> type and x-txt a non-picklist.
>>
>> <?xml version='1.0' ?>
>> <tmx xmlns:x-TXT="http://www.x-txt.org" 
>> xmlns:x-ALS="http://www.x-als.org">
>> <tu>
>>    <x-ALS:Status>Approved</x-ALS:Status>
>>    <x-ALS:Department>Marketing</x-ALS:Department>
>>    <x-ALS:DocType>Internet</x-ALS:DocType>
>>    <x-TXT:DocName>Update</x-TXT:DocName>
>> </tu>
>> ......
>>
>> When I load the XML the datagrid columns are called Status, 
>> Department, etc. And not x-ALS:Status as I initially expected. If this 
>> information was not stripped from the column name it would help me 
>> identify the column type. Do I need to preprocess the XML file to 
>> transfer this information to the column title? i.e.
>> ....
>> <tu>
>>    <x-ALS:ALS_Status>Approved</x-ALS:Status>
>>    <x-ALS:ALS_Department>Marketing</x-ALS:Department>
>>    <x-ALS:ALS_DocType>Internet</x-ALS:DocType>
>>    <x-TXT:ALS_DocName>Update</x-TXT:DocName>
>> </tu>
> 
> That's a strange way of indicating data type, but check the 
> DataColumn.Namespace property after you load.

Hi John,

thanks for your help. It's annoying when you see how simple the solution 
is. But I suppose that the difference between real programmers and hobby 
programmers like me :-)

regards,

Rob
0
7/8/2007 5:05:02 PM
"Robert Bevington" <rbevington@freenet.de> wrote in message 
news:ubclfIYwHHA.1208@TK2MSFTNGP03.phx.gbl...
> John Saunders [MVP] schrieb:
....
>> That's a strange way of indicating data type, but check the 
>> DataColumn.Namespace property after you load.
>
> Hi John,
>
> thanks for your help. It's annoying when you see how simple the solution 
> is. But I suppose that the difference between real programmers and hobby 
> programmers like me :-)

Well, I think it's more the difference between programmers who have a life, 
and programmers who pour through the documentation looking for new and 
exciting properties and methods.  I started with .NET back in the .NET 1.0 
beta days, and there were no books. So I printed the MSDN library docs. I 
still have about 20 of the binders I used, as well as the electric 
three-hole punch!

IOW, I memorized System.Data.DataColumn.Namespace about six years ago! 
Didn't know what it meant until I started working with XML!
-- 
John Saunders [MVP]

0
John
7/8/2007 6:05:08 PM
Reply:

Similar Artilces:

Why is XMLSchema namespace so different than my custom namespace?
Below is a snippet that I'm sure is quite familiar to most ... <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" Here, I've given the XMLSchema namespace the prefix 'xsd', and with that, I can reference datatypes within the XMLSchema namespace ... i.e., xsd:string. That's great, but why can't I use that same notation, to reference dataypes in a homegrown schema ... WITHOUT doing an <import> or <include>? Is the XMLSchema (and the XMLSchema-instance) sort of "built-in" to XML tools, such that they don't need to go find th...

Namespaces
Is there any documentations that will explain the Namespaces better or any help file? -- Matthew Heinrich Casino Queen Inc. Development Team ...

XmlSerializer and blank namespace
In 1.1, I could do this: XmlSerializer xs = new XmlSerializer(typeof(Doodad)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.add("", ""); xs.Serialize(writer, doodad, ns); and it produced: <doodad> .... </doodad> In 2.0, the same code produces: <doodad xmlns=""> .... </doodad> Any idea why and how to get rid of the blank namespace? ...

XML namespaces and XSD.exe
Oh boy i'm getting tangled in knots here. I have a schema which contains <xs:schema targetNamespace="http://Southend.Schemas.PAS/PASPatientDemographics.xsd" id="PASPatientDetails" xmlns:sh="http://Southend.Schemas.PAS/PASPatientDemographics.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> now i used the xsd.exe and it now generates elements when I serilaize the class I get <RequestingPatient_ID xmlns="">D1234567890</RequestingPatient_ID> So each emlement contains xmlns=&qu...

Xpath with namespaces
Hello Everyone, I am having an issue with xml and namespaces, at least I think it is namespaces. When I use namespaces, I cannot use SelectSingleNode / SelectNodes as they always return 0/Nothing respectively. Anyone have any thoughts? Thanks in advance VB.Net 2005 WinXP Sp2 Test code: Dim objXML As System.Xml.XmlDocument 'Test XML 1 ==> Always returns 0 objXML = New System.Xml.XmlDocument objXML.Load(Application.StartupPath & "\xmlfile1.xml") MsgBox(objXML.SelectNodes("top/middle").Count) 'Test XML 2 ==> Always re...

Redundant namespace descriptors
Using this target schema: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=24480 I generate this xml: http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=24481 using the VS editor. For the boolean attribute 'Selected' in the Answer tags a complete namespace is redefined xmlns:d3p1="http://tempuri.org/QuizData.xsd." This seems pretty redundant to me and would lead to some awful code bloat in a large file. Is there any way to fix this so that I not generating a new namespace definition in every tag? ...

Read ony special rows with ReadXml()
Hi. With DataSet.ReadXml() i can read the _complete_ XML data into a DataSet. Is it possible to read only special rows of the data or to filter the XML data before reading? thanks and best regards, jan Your best bet would be to build a custom XmlReader to filter the content, if the problem warrants that much work. A more flexible approach would be you to apply an XSLT on the input document before you load it into the DataSet. -- HTH Christoph Schittko [MVP, XmlInsider] Software Architect, .NET Mentor "Jan Weing�rtner" <jweingart@gmx.de> wrote in message news:uAgNDvu7DHA....

Conditional namespace
Hi Everyone, I want to include the namespace "using Windows7.DesktopIntegration" in my C# project only if the current OS is Windows 7, for other OS like Xp,2000,vista I need to ignore the same. Any idea for achieving this will helpful for me. -- Thanks and Regards, Shankar B. Shankar wrote: > Hi Everyone, > > I want to include the namespace "using Windows7.DesktopIntegration" in my C# > project only if the current OS is Windows 7, for other OS like Xp,2000,vista > I need to ignore the same. > I'm puzzled. AFAIK the only r...

Testing for non-existing namespace attribute?
Hello! I'm using msxml3 in the C++ environment, VC 7.1.3088. How do I know if the namespace attribute doesn't exist? I want to put it in a std::string, and I try to do that like this: string CXmlNodeWrapper::GetNamespaceURI() const { if( IsValid() ) { _bstr_t str = m_xmlnode->GetnamespaceURI(); return static_cast<char*>(str); // <- point of exception } return ""; } m_xmlnode is a MSXML2::IXMLDOMNodePtr; This works fine as long as there is a namespace attribute, but if the root node doesn't have a namespace attribute thi...

SelectSingleNode and Namespace
This is a multi-part message in MIME format. ------=_NextPart_000_0006_01C54429.49A1B710 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, I use a XML-Doc with a Namespace like the following example: <HomedResources = xmlns=3Dhttp://schemas.microsoft.com/RtcServer/2002/11/dbimpexp = Version=3D"3"> <HomedResource UserAtHost=3D"PBoul@team.de" Enabled=3D"1" = VersionPermission=3D"10" =20 VersionContact=3D"25" DisplayName=3D"Boullay, Peter" = Email=3...

Serializing Class with Unqualified Root Element and Default Namespace attribute
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified, and the default namespace needs to be included on it as an attribute. The schema I'm using is this: <xs:schema xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:xs="http://www...

XPathNavigation and Namespaces.
I have the following code that is attempting to read nodes from an xml file... XmlDocument xpdStatus = new XmlDocument(); xpdStatus.Load("status.xml"); XPathNavigator xpnStatus = xpdStatus.CreateNavigator(); XPathNodeIterator xpniStatus = xpnStatus.Select("descendant::Status"); while (xpniStatus.MoveNext()) { Console.WriteLine("Book title: {0}", xpniStatus.Current.Value); XmlNode node = ((xpniStatus.Current) as IHasXmlNode).GetNode(); Console.WriteLine("Status: {0}", node.Value); } The code works fine until I attempt to add namespaces, with prefixes...

Xpath Search with Namespaces
I've run into a problem trying to search an XML document with a namespace. Sample extract is below: <Vendors xmlns="http://tempuri.org/Vendor.xsd"> <Vendor> <VendorID>002010</VendorID> <PropricerId>002010S</PropricerId> <VendorName>AEROTEK, INC.</VendorName> </Vendor> <Vendor> <VendorID>002012</VendorID> <PropricerId>002012S</PropricerId> <VendorName>ARONSON &amp; COMPANY</VendorName> </Vendor> <Vendor> <VendorID>002018</VendorID> <P...

Problem with ReadXml into DataSet
Hello! I have created a xml-file by using the writeXml method on a dataset. The problem arrises when I want to read the xml-file back into a dataset on a pocket pc application. Some of the fields which are strings have whitespaces added to end of the values in the dataset but not in the xml-file. How do I read the xml-file without getting the whitespaces? This is a part of the xml-file: - <User> <Username>hoa</Username> <Password>hoa</Password> <Access>1</Access> </User> and when it's put into the dataset it's like thi...

Adding Namespaces to Outlook Possible?
I'm a developer that have on a number of occasions written namespace extentions for the windows shell (Windows Explorer). I have a need to do something similar with Outlook. I would like to be able to write a namespace extention to Outlook allowing me to add a hierarchy to the tree or folder view and handle the listview myself. Just like a namespace extention in windows explorer. I have done some internet searches and come up empty so my guess is that this is not supported or documented. However if it is possible and the interfaces are named and documented then this would be a real bo...

Namespaces ?
What see sample that show xs:element where the xs namespace = http://www.w3.org/2001/XMLSchema However, I see another example with xsi: where xsi = http://www.w3.org/2001/XMLSchema-instance What's the difference here? Are there right and wrong namespaces? Is there a global list of the ones to use? Does the namespace even need to point at http://www.w3.org.....? Or is this just the accepted way? Very appreciative, Mike Morse They are different namespaces that refer to different things. for more on XML Namespaces, See http://www.w3.org/TR/REC-xml-names/ http://msdn.microsoft.com/...

Problem with XML Namespace
Hello, As a VB6 programmer, I'm quite a newbee in .NET. I'm working with Visual Studio .NET 2005 Beta2 and try write a class that reads an online xml document. Let's say, something you would do with XmlHttp in VB6. My problem is, that my GUI does not recornize the System.xml namespace. I get this error: "namespace or type specified in the imports 'System.xml' cannot be found" Why do I get this error? Thanks, Ramon. Ramon wrote: > As a VB6 programmer, I'm quite a newbee in .NET. > > I'm working with Visual Studio .NET 2005 Beta2 and try...

Using XPath with namespaces
Hello, I have been trying to get data from an xml file with a namespace. I have followed the example in the MSDN, but I get no data in t he XPathNodeIterator, but the file has the data I am trying to extract. ... XPathNavigator navigator = xmlDoc.CreateNavigator(); // xpathQuery = "/ProductInformation/ProductNumber" XPathExpression expr = navigator.Compile( xpathQuery ); expr = navigator.Compile( xpathQuery ); XmlNamespaceManager nsmgr = new XmlNamespaceManager( navigator.NameTable ); nsmgr.AddNamespace( "myNS", "http://www.orange.com/schemas/imaging/cyanblue/dev/1...

What happens to dataset with multiple ReadXML()'s?
FYI: ASP.NET application: First DS.ReadXML reads/loads data fine. The second DS.ReadXML doesn't throw an exception, but I can't find data from the 2nd DS.ReadXML() ?? Any idea where the data is going??? TIA! -Scott Fenstermacher sfenstermacher@lrs.com Nevermind, it works now... "Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message news:MPG.1b0563f92f6e5c55989680@msnews.microsoft.com... > FYI: ASP.NET application: > > First DS.ReadXML reads/loads data fine. The second DS.ReadXML doesn't > throw an exception, but I can't find data f...

XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem.
Hi, I can't for the life of me get this to work properly. I've searched for examples, but none of the examples quite match my environment. Here is my XML (please treat this as immutable -- no solutions involving altering the XML are good for me): ---- config.xml ---- <Configuration xmlns="urn:server:schemas:configuration" xmlns:f="urn:server:schemas:faq"> <version version="0.0.0001"> <f:faq> <f:section>Default</f:section> <f:item> <f:q>What is the mean...

domain namespace
I have an internal domain (Example: joe.ad) and external domain (joe.com) but I don't want my internal domain to be publicly accessible but able to route mail in/out? Please provide more detail what you're trying to accomplish. -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!" "souldog" <souldog@discussions.microsoft.com> wrote in message news:0F30A075-9096-4190-9325-47AA7BE9EE16@microsoft.com... >I have an internal domain (Example: joe.ad) and external domain (joe.com) >but > I don't want my internal domain t...

namespace of AfxLoadLibrary
Hi, I did not find in which namespace is define AfxLoadLibrary(). I'm migrating my app under .NET and as i did not find something useful in .NET (event if DllimportAttribute exists), i would like to mix MFC and .NET in a class. thanks a lot, Alain "--== Alain ==--" <nospam@noemail.com> wrote in message news:uoWGEF67GHA.3340@TK2MSFTNGP04.phx.gbl... > Hi, > > I did not find in which namespace is define AfxLoadLibrary(). This is a MFC method and this does not have a namespace as .Net does or perhpas its what you may call a global namespace. You should be able ...

XPath and namespaces
Hi; First off, I think I still do not understand exactly how we are supposed to handle namespaces when doing xpath queries under .NET so I may have some bad assumptions here. As I understand it, we need to set the namespaces on an XmlDocument - the ..NET libraries do not read it from the xmlns:... attributes in the xml. In our case we have to handle xml our customers will pass to our library so we do not know up front what namespaces will be in there or how they are set up. So we do the following: private void SetNamespace(XPathNavigator nav) { XPathNodeIterator list = nav.Select...

XML namespaces and VB.Net
I posted this a few days ago and didn't get any response. I try again but ask it a little differently. I'm recieving any XML document from a client and I need to convert it to an ASCII delimited string to input into a legacy system. I've put together a VB.Net class that does this using DOM commands such as SelectSingleNode(). It works fine but I've noticed that it can not read past inbedded namespaces that are found throghout the document. I don't use namespaces in my own XML document so I do not know how to make this work or if I can. The system they are usi...

XPath with namespace
Hello all, I am working on an Add-in to the .NET framework using C#. I wanted to search the XML document using XPath but failed. The XML is like this: <unit xmlns="http://www.some.info/srcML" xmlns:cpp="http://www.some.info/srcML/cpp"> <aaa>something</aaa> </unit> The code I am using is as follows: XPathNavigator nav; XPathDocument docNav; XPathNodeIterator NodeIter; string fname="sth.xml"; docNav = new XPathDocument(@fname); nav = docNav.CreateNavigator(); nav.Evaluate(input); NodeIter = nav.Select(input); It works fine if there is n...