Visa

Visa

  • NA
  • 1
  • 0

Xpath and namaspacemanager problems..

Jul 21 2005 1:34 AM
This is really bugging me..

I have an xml file were I want to get info by doing a xpath query with SelectSingleNode and SelectNodes.
.Net requires you to use namespacemanager, but I cant get it work. The query just gives me null.

When I take my namespace xmlns=".." from the root element away then it works.
Here is the code and xml file...could someone help me please?
c#:

try

{

XmlDocument doc = new XmlDocument();

doc.Load("sampleXML.xml");

System.Xml.XmlNamespaceManager nsmg = new System.Xml.XmlNamespaceManager(doc.NameTable);

nsmg.AddNamespace("test", http://www.test.com);

//Lasketaan alignments:ien määrä tiedostossa

int alignments;

alignments = doc.SelectNodes("//test:Alignment", nsmg).Count; //return null

MessageBox.Show(alignments.ToString());

}

catch(Exception ex)

{
MessageBox.Show(ex.ToString());
}



xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<LandXML xmlns="http://www.landxml.org/schema/LandXML-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.landxml.org/schema/LandXML-1.0 http://www.landxml.org/schema/LandXML-1.0/LandXML-1.0.xsd"  date="2005-06-07" time="12:47:44" version="1.0">
 <Units>
  <Metric areaUnit="squareMeter" linearUnit="meter" volumeUnit="cubicMeter" temperatureUnit="celsius" pressureUnit="mmHG" angularUnit="radians" directionUnit="radians"/>
 </Units>
 <Application name="Novapoint" manufacturer="ViaNova Systems AS" version="16.1000" manufacturerURL="www.novapoint.com">
  <Author createdBy="fin-admin"/>
 </Application>
 <Project/>
 <Alignments name="1001">
  <Alignment name="1082_JOVA" length="4771.237217" staStart="0.000000">
   <CoordGeom>
    
    <Line staStart="4474.167748" length="297.069471">
     <Start>6898657.303415 3544669.113915</Start>
     <End>6898952.704715 3544700.551827</End>
    </Line>
   </CoordGeom>
  </Alignment>
 </Alignments>
</LandXML>