现在我有这样一个xml文件:<?xml version="1.0" encoding="UTF-8"?>
<!-- Example of Well data -->
<wells
xmlns="http://www.witsml.org/schemas/1series"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.witsml.org/schemas/1series ../xsd_schemas/obj_well.xsd"
version="1.4.0.0">
<!--
These examples are only intended to demonstrate the type of data that can be exchanged.
They totally artificial and are not intended to demonstrate best practices.
-->
<documentInfo>
<documentName>well</documentName>
<fileCreationInformation>
<fileCreationDate>2001-10-31T08:15:00.000Z</fileCreationDate>
<fileCreator>John Smith</fileCreator>
</fileCreationInformation>
</documentInfo>
<well uid="w-12">
<name>6507/7-A-42</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<dTimLicense>2001-05-15T13:20:00.000Z</dTimLicense>
<field>Big Field</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>
<operatorDiv>Division Name</operatorDiv>
<pcInterest uom="%">65</pcInterest>
<numAPI>123-543-987AZ</numAPI>
<statusWell>drilling</statusWell>
<purposeWell>exploration</purposeWell>
<dTimSpud>2001-05-31T08:15:00.000Z</dTimSpud>
<dTimPa>2001-07-15T15:30:00.000Z</dTimPa>
<wellheadElevation uom="ft">500</wellheadElevation>
<wellDatum uid="KB" defaultMeasuredDepth="true" defaultVerticalDepth="true">
<name>Kelly Bushing</name>
<code>KB</code>
<elevation uom="ft" datum="SL">78.5</elevation>
</wellDatum>
<wellDatum uid="SL" defaultElevation="true">
<name>Sea Level</name>
<code>SL</code>
</wellDatum>
<groundElevation uom="ft">250</groundElevation>
<waterDepth uom="ft">520</waterDepth>
<wellLocation uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
<description>Location of well surface point in projected system.</description>
</wellLocation>
<referencePoint uid="SRP1">
<name>Slot Bay Centre</name>
<type>Site Reference Point</type>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425366.47</easting>
<northing uom="m">6623781.95</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="localWell1">WellOneWSP</wellCRS>
<localX uom="m">12.63</localX>
<localY uom="m">-3.74</localY>
<description>Location of the Site Reference Point with respect to the well surface point</description>
</location>
</referencePoint>
<referencePoint uid="WRP2">
<name>Sea Bed</name>
<type>Well Reference Point</type>
<elevation uom="ft" datum="SL">-118.40</elevation>
<measuredDepth uom="ft" datum="KB">173.09</measuredDepth>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="geog1">ED50</wellCRS>
<latitude uom="dega">59.743844</latitude>
<longitude uom="dega">1.67198083</longitude>
</location>
</referencePoint>
<wellCRS uid="geog1">
<name>ED50</name>
<geodeticCRS uidRef="4230">4230</geodeticCRS >
<description>ED50 system with EPSG code 4230.</description>
</wellCRS>
<wellCRS uid="proj1">
<name>ED50 / UTM Zone 31N</name>
<mapProjectionCRS uidRef="23031">ED50 / UTM Zone 31N</mapProjectionCRS>
</wellCRS>
<wellCRS uid="localWell1">
<name>WellOneWSP</name>
<localCRS>
<usesWellAsOrigin>true</usesWellAsOrigin>
<yAxisAzimuth uom="dega" northDirection="grid north">0</yAxisAzimuth>
<xRotationCounterClockwise>false</xRotationCounterClockwise>
</localCRS>
</wellCRS>
<commonData>
<dTimCreation>2001-04-30T08:15:00.000Z</dTimCreation>
<dTimLastChange>2001-05-31T08:15:00.000Z</dTimLastChange>
<itemState>plan</itemState>
<comments>These are the comments associated with the Well data object.</comments>
</commonData>
</well>
<well uid="w-13">
<name>6507/7-A-42</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<dTimLicense>2001-05-15T13:20:00.000Z</dTimLicense>
<field>Big Field</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>
<operatorDiv>Division Name</operatorDiv>
<pcInterest uom="%">65</pcInterest>
<numAPI>123-543-987AZ</numAPI>
<statusWell>drilling</statusWell>
<purposeWell>exploration</purposeWell>
<dTimSpud>2001-05-31T08:15:00.000Z</dTimSpud>
<dTimPa>2001-07-15T15:30:00.000Z</dTimPa>
<wellheadElevation uom="ft">500</wellheadElevation>
<wellDatum uid="KB" defaultMeasuredDepth="true" defaultVerticalDepth="true">
<name>Kelly Bushing</name>
<code>KB</code>
<elevation uom="ft" datum="SL">78.5</elevation>
</wellDatum>
<wellDatum uid="SL" defaultElevation="true">
<name>Sea Level</name>
<code>SL</code>
</wellDatum>
<groundElevation uom="ft">250</groundElevation>
<waterDepth uom="ft">520</waterDepth>
<wellLocation uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
<description>Location of well surface point in projected system.</description>
</wellLocation>
<referencePoint uid="SRP1">
<name>Slot Bay Centre</name>
<type>Site Reference Point</type>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425366.47</easting>
<northing uom="m">6623781.95</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="localWell1">WellOneWSP</wellCRS>
<localX uom="m">12.63</localX>
<localY uom="m">-3.74</localY>
<description>Location of the Site Reference Point with respect to the well surface point</description>
</location>
</referencePoint>
<referencePoint uid="WRP2">
<name>Sea Bed</name>
<type>Well Reference Point</type>
<elevation uom="ft" datum="SL">-118.40</elevation>
<measuredDepth uom="ft" datum="KB">173.09</measuredDepth>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="geog1">ED50</wellCRS>
<latitude uom="dega">59.743844</latitude>
<longitude uom="dega">1.67198083</longitude>
</location>
</referencePoint>
<wellCRS uid="geog1">
<name>ED50</name>
<geodeticCRS uidRef="4230">4230</geodeticCRS >
<description>ED50 system with EPSG code 4230.</description>
</wellCRS>
<wellCRS uid="proj1">
<name>ED50 / UTM Zone 31N</name>
<mapProjectionCRS uidRef="23031">ED50 / UTM Zone 31N</mapProjectionCRS>
</wellCRS>
<wellCRS uid="localWell1">
<name>WellOneWSP</name>
<localCRS>
<usesWellAsOrigin>true</usesWellAsOrigin>
<yAxisAzimuth uom="dega" northDirection="grid north">0</yAxisAzimuth>
<xRotationCounterClockwise>false</xRotationCounterClockwise>
</localCRS>
</wellCRS>
<commonData>
<dTimCreation>2001-04-30T08:15:00.000Z</dTimCreation>
<dTimLastChange>2001-05-31T08:15:00.000Z</dTimLastChange>
<itemState>plan</itemState>
<comments>These are the comments associated with the Well data object.</comments>
</commonData>
</well>
</wells>我想在其中查找所有well节点,我这样做没有没有得到任何结果:
XmlNodeList nodeWell = wells.SelectNodes("//wells/well");
怎么回事?
<!-- Example of Well data -->
<wells
xmlns="http://www.witsml.org/schemas/1series"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.witsml.org/schemas/1series ../xsd_schemas/obj_well.xsd"
version="1.4.0.0">
<!--
These examples are only intended to demonstrate the type of data that can be exchanged.
They totally artificial and are not intended to demonstrate best practices.
-->
<documentInfo>
<documentName>well</documentName>
<fileCreationInformation>
<fileCreationDate>2001-10-31T08:15:00.000Z</fileCreationDate>
<fileCreator>John Smith</fileCreator>
</fileCreationInformation>
</documentInfo>
<well uid="w-12">
<name>6507/7-A-42</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<dTimLicense>2001-05-15T13:20:00.000Z</dTimLicense>
<field>Big Field</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>
<operatorDiv>Division Name</operatorDiv>
<pcInterest uom="%">65</pcInterest>
<numAPI>123-543-987AZ</numAPI>
<statusWell>drilling</statusWell>
<purposeWell>exploration</purposeWell>
<dTimSpud>2001-05-31T08:15:00.000Z</dTimSpud>
<dTimPa>2001-07-15T15:30:00.000Z</dTimPa>
<wellheadElevation uom="ft">500</wellheadElevation>
<wellDatum uid="KB" defaultMeasuredDepth="true" defaultVerticalDepth="true">
<name>Kelly Bushing</name>
<code>KB</code>
<elevation uom="ft" datum="SL">78.5</elevation>
</wellDatum>
<wellDatum uid="SL" defaultElevation="true">
<name>Sea Level</name>
<code>SL</code>
</wellDatum>
<groundElevation uom="ft">250</groundElevation>
<waterDepth uom="ft">520</waterDepth>
<wellLocation uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
<description>Location of well surface point in projected system.</description>
</wellLocation>
<referencePoint uid="SRP1">
<name>Slot Bay Centre</name>
<type>Site Reference Point</type>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425366.47</easting>
<northing uom="m">6623781.95</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="localWell1">WellOneWSP</wellCRS>
<localX uom="m">12.63</localX>
<localY uom="m">-3.74</localY>
<description>Location of the Site Reference Point with respect to the well surface point</description>
</location>
</referencePoint>
<referencePoint uid="WRP2">
<name>Sea Bed</name>
<type>Well Reference Point</type>
<elevation uom="ft" datum="SL">-118.40</elevation>
<measuredDepth uom="ft" datum="KB">173.09</measuredDepth>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="geog1">ED50</wellCRS>
<latitude uom="dega">59.743844</latitude>
<longitude uom="dega">1.67198083</longitude>
</location>
</referencePoint>
<wellCRS uid="geog1">
<name>ED50</name>
<geodeticCRS uidRef="4230">4230</geodeticCRS >
<description>ED50 system with EPSG code 4230.</description>
</wellCRS>
<wellCRS uid="proj1">
<name>ED50 / UTM Zone 31N</name>
<mapProjectionCRS uidRef="23031">ED50 / UTM Zone 31N</mapProjectionCRS>
</wellCRS>
<wellCRS uid="localWell1">
<name>WellOneWSP</name>
<localCRS>
<usesWellAsOrigin>true</usesWellAsOrigin>
<yAxisAzimuth uom="dega" northDirection="grid north">0</yAxisAzimuth>
<xRotationCounterClockwise>false</xRotationCounterClockwise>
</localCRS>
</wellCRS>
<commonData>
<dTimCreation>2001-04-30T08:15:00.000Z</dTimCreation>
<dTimLastChange>2001-05-31T08:15:00.000Z</dTimLastChange>
<itemState>plan</itemState>
<comments>These are the comments associated with the Well data object.</comments>
</commonData>
</well>
<well uid="w-13">
<name>6507/7-A-42</name>
<nameLegal>Company Legal Name</nameLegal>
<numLicense>Company License Number</numLicense>
<numGovt>Govt-Number</numGovt>
<dTimLicense>2001-05-15T13:20:00.000Z</dTimLicense>
<field>Big Field</field>
<country>US</country>
<state>TX</state>
<county>Montgomery</county>
<region>Region Name</region>
<district>District Name</district>
<block>Block Name</block>
<timeZone>-06:00</timeZone>
<operator>Operating Company</operator>
<operatorDiv>Division Name</operatorDiv>
<pcInterest uom="%">65</pcInterest>
<numAPI>123-543-987AZ</numAPI>
<statusWell>drilling</statusWell>
<purposeWell>exploration</purposeWell>
<dTimSpud>2001-05-31T08:15:00.000Z</dTimSpud>
<dTimPa>2001-07-15T15:30:00.000Z</dTimPa>
<wellheadElevation uom="ft">500</wellheadElevation>
<wellDatum uid="KB" defaultMeasuredDepth="true" defaultVerticalDepth="true">
<name>Kelly Bushing</name>
<code>KB</code>
<elevation uom="ft" datum="SL">78.5</elevation>
</wellDatum>
<wellDatum uid="SL" defaultElevation="true">
<name>Sea Level</name>
<code>SL</code>
</wellDatum>
<groundElevation uom="ft">250</groundElevation>
<waterDepth uom="ft">520</waterDepth>
<wellLocation uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
<description>Location of well surface point in projected system.</description>
</wellLocation>
<referencePoint uid="SRP1">
<name>Slot Bay Centre</name>
<type>Site Reference Point</type>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425366.47</easting>
<northing uom="m">6623781.95</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="localWell1">WellOneWSP</wellCRS>
<localX uom="m">12.63</localX>
<localY uom="m">-3.74</localY>
<description>Location of the Site Reference Point with respect to the well surface point</description>
</location>
</referencePoint>
<referencePoint uid="WRP2">
<name>Sea Bed</name>
<type>Well Reference Point</type>
<elevation uom="ft" datum="SL">-118.40</elevation>
<measuredDepth uom="ft" datum="KB">173.09</measuredDepth>
<location uid="loc-1">
<wellCRS uidRef="proj1">ED50 / UTM Zone 31N</wellCRS>
<easting uom="m">425353.84</easting>
<northing uom="m">6623785.69</northing>
</location>
<location uid="loc-2">
<wellCRS uidRef="geog1">ED50</wellCRS>
<latitude uom="dega">59.743844</latitude>
<longitude uom="dega">1.67198083</longitude>
</location>
</referencePoint>
<wellCRS uid="geog1">
<name>ED50</name>
<geodeticCRS uidRef="4230">4230</geodeticCRS >
<description>ED50 system with EPSG code 4230.</description>
</wellCRS>
<wellCRS uid="proj1">
<name>ED50 / UTM Zone 31N</name>
<mapProjectionCRS uidRef="23031">ED50 / UTM Zone 31N</mapProjectionCRS>
</wellCRS>
<wellCRS uid="localWell1">
<name>WellOneWSP</name>
<localCRS>
<usesWellAsOrigin>true</usesWellAsOrigin>
<yAxisAzimuth uom="dega" northDirection="grid north">0</yAxisAzimuth>
<xRotationCounterClockwise>false</xRotationCounterClockwise>
</localCRS>
</wellCRS>
<commonData>
<dTimCreation>2001-04-30T08:15:00.000Z</dTimCreation>
<dTimLastChange>2001-05-31T08:15:00.000Z</dTimLastChange>
<itemState>plan</itemState>
<comments>These are the comments associated with the Well data object.</comments>
</commonData>
</well>
</wells>我想在其中查找所有well节点,我这样做没有没有得到任何结果:
XmlNodeList nodeWell = wells.SelectNodes("//wells/well");
怎么回事?
XmlDocument doc = new XmlDocument();
doc.Load(xml路径)
XmlNodeList nodeWell = doc.GetElementsByTagName("well")
<logs>
<log uidWell="W-12" uidWellbore="B-0" uid="f34a">
<nameWell>6507/7-A-42</nameWell>
<nameWellbore>A-42</nameWellbore>
<name>L001</name>
</log>
</logs>使用语句:
XmlNode nodeUid = xIn.SelectSingleNode("//log");
就可以查找的log节点,但是对那个内容较多的xml文档,SelectSingleNode和SelectNodes就不好用了
<wells
xmlns="http://www.witsml.org/schemas/1series"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.witsml.org/schemas/1series ../xsd_schemas/obj_well.xsd"
version="1.4.0.0">
多了 xmlns="http://www.witsml.org/schemas/1series"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.witsml.org/schemas/1series ../xsd_schemas/obj_well.xsd"
version="1.4.0.0">
如果没有这些,就可以了
doc.Load("xml路径");
XmlNodeList wells = doc.SelectNodes("wells/well");
_Document.Load(@"D:\temp\file1.xml"); System.Xml.XmlNamespaceManager _NamespaceManager = new System.Xml.XmlNamespaceManager(_Document.NameTable);
_NamespaceManager.AddNamespace("Name", _Document.DocumentElement.NamespaceURI); System.Xml.XmlNodeList _List = _Document.SelectNodes("//Name:well", _NamespaceManager);
{
string str = null;
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("1.xml");
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDocument.NameTable);
xnm.AddNamespace("XNM", "http://www.witsml.org/schemas/1series");
XmlNodeList mynodelist = xmlDocument.SelectNodes("/XNM:wells/XNM:well", xnm);
int index;
for (index = 0; index < mynodelist.Count; index++)
{
XmlElement root = xmlDocument.DocumentElement;
if (mynodelist.Count.ToString() != null)
{
str+= mynodelist.Item(index).InnerText;
} }
Console.WriteLine(str);
Console.ReadKey(); }
XmlNode nodelist = doc.SelectSingleNode("wells/well[@uid='w-12']");这个是没有命名空间的情况,如果有命名空间的话,你可以按照zgke的尝试一下这样加一下
{
string str = null;
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("1.xml");
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDocument.NameTable);
xnm.AddNamespace("XNM", "http://www.witsml.org/schemas/1series");
XmlNodeList mynodelist = xmlDocument.SelectNodes("/XNM:wells/XNM:well[@uid=\"w-12\"]", xnm);
int index;
for (index = 0; index < mynodelist.Count; index++)
{
XmlElement root = xmlDocument.DocumentElement;
if (mynodelist.Count.ToString() != null)
{
str+= mynodelist.Item(index).InnerText;
} }
Console.WriteLine(str);
Console.ReadKey(); }
ode nodelist = doc.SelectSingleNode("wells/well[@uid='”+变量+“']");