|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Detect Default namespace (Unkown)are occasions whe the default namesapce will change and i need to account for it. The namespace can be xmlns="http://data.usgs.gov/mag/1.0" or xmlns="http://data.usgs.gov/mag/2.0" or xmlns="http://data.usgs.gov/dec/2.8" These are examples and there could be many more.The data is more or less in the same format as far as nodes and node names but how do I account for the various namespaces. I will not know these ahead of time so was hoping there was a way to parse these out of the header. tia AGP That should be possible, depends on how you're processing the XML.
For example if you are using System.Xml.XmlDocument which has an identifier of doc then you can read the doc.DocumentElement.NamepaceURI property, assuming the default namespace is declared at the top level. http://msdn.microsoft.com/en-us/library/system.xml.xmlelement.namespaceuri.aspx Show quoteHide quote "AGP" <sindizzy.***@softhome.net> wrote in message news:vDZ2m.3331$bq1.302@nlpi066.nbdc.sbc.com... > I am trying to parse out an XMl file and have it all working except there > are occasions whe the default namesapce will change and i need to account > for it. The namespace can be > > xmlns="http://data.usgs.gov/mag/1.0" > > or > > xmlns="http://data.usgs.gov/mag/2.0" > > or > > xmlns="http://data.usgs.gov/dec/2.8" > > These are examples and there could be many more.The data is more or less > in the same format as far as nodes and node names but how do I account for > the various namespaces. I will not know these ahead of time so was hoping > there was a way to parse these out of the header. > > tia > > AGP > thanks. i think this will work. Incidentally if there are more than one
namespaeces how do I parse those out? I dont think Ill need them but i think its good info to know. AGP Abel Show quoteHide quote "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message news:%23Nyts8u%23JHA.1608@TK2MSFTNGP02.phx.gbl... > That should be possible, depends on how you're processing the XML. > For example if you are using System.Xml.XmlDocument which has an > identifier of doc then you can read the doc.DocumentElement.NamepaceURI > property, assuming the default namespace is declared at the top level. > > http://msdn.microsoft.com/en-us/library/system.xml.xmlelement.namespaceuri.aspx > > > -- > > Joe Fawcett (MVP - XML) > http://joe.fawcett.name > > > "AGP" <sindizzy.***@softhome.net> wrote in message > news:vDZ2m.3331$bq1.302@nlpi066.nbdc.sbc.com... >> I am trying to parse out an XMl file and have it all working except there >> are occasions whe the default namesapce will change and i need to account >> for it. The namespace can be >> >> xmlns="http://data.usgs.gov/mag/1.0" >> >> or >> >> xmlns="http://data.usgs.gov/mag/2.0" >> >> or >> >> xmlns="http://data.usgs.gov/dec/2.8" >> >> These are examples and there could be many more.The data is more or less >> in the same format as far as nodes and node names but how do I account >> for the various namespaces. I will not know these ahead of time so was >> hoping there was a way to parse these out of the header. >> >> tia >> >> AGP >> > > > AGP wrote:
Show quoteHide quote > I am trying to parse out an XMl file and have it all working except there Do you use LINQ to XML to deal with the XML? If so then you can simply do> are occasions whe the default namesapce will change and i need to account > for it. The namespace can be > > xmlns="http://data.usgs.gov/mag/1.0" > > or > > xmlns="http://data.usgs.gov/mag/2.0" > > or > > xmlns="http://data.usgs.gov/dec/2.8" > > These are examples and there could be many more.The data is more or less in > the same format as far as nodes and node names but how do I account for the > various namespaces. I will not know these ahead of time so was hoping there > was a way to parse these out of the header. Dim doc As XDocument = XDocument.Load("file.xml") Dim ns As XNamespace = doc.Root.Name.Namespace to get an XNamespace object, assuming the default namespace is defined on the root element of your XML documents. Then you can use that XNamespace object ns when trying to select elements e.g. Dim query = _ From foo In doc.Descendants(ns + "foo") _ ... The nice thing is that the approach even works if the root element has no namespace declaration so you don't have to change the code if you need to deal with different documents where some have a namespace and some do not have one.
vb.net and Ms SQL Connection ?
Using "Me" Using WPF with a "normal" windows app Unable to connect to the remote server How to reference class properties using MyClass("PropertyName") VB Net/Com Interoperability/Late Binding Serializing Custom Generic Collection (Of InterfaceType) DataGridView Event Web server is not running ASP.NET version 1.1. Add Line Break to mail body |
|||||||||||||||||||||||