473,466 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Navigating DOM with XPath in .NET

I have following xml file and I want to read <EquipmentClass> tag and it's Text.This xml file implements B2MML schema and hence xml file structure is not the usual one.Does anybody know how to ahieve the result?I tried using "SelectNodes" method but it doesn't work

<?xml version = "1.0" encoding = "UTF-8"?><EquipmentInformation xmlns = "http://www.wbf.org/xml/b2mml-v02" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.wbf.org/xml/b2mml-v02 file:B2MML-V02-Equipment.xsd"><ID>EquipmentInformation.BigCorp</ID><Description>The very first test load for Equipment Information</Description><Description>This will test multiple description lines</Description><Location><EquipmentID>BigCorp</EquipmentID><EquipmentElementLevel>Enterprise</EquipmentElementLevel></Location><PublishedDate>2004-02-01T03:49:00.000</PublishedDate><Equipment><ID>BigCorp</ID><Description>Represents the BigCorp Enterprise, a ficticious enterprise used as part of initial test data for the model</Description><Equipment><ID>HoustonTX</ID><Description>Big Corp Houston TX site</Description><Description>This site has Refining operations (big suprise!)</Description><Description>This is an example of a Continuous Manufacturing facility</Description><Equipment><ID>CrudeTankFarm</ID></Equipment><Equipment><ID>CrudeDistillationArea</ID><Location><EquipmentID>CrudeDistillationArea</EquipmentID><EquipmentElementLevel>Area</EquipmentElementLevel></Location></Equipment><Equipment><ID>SaturatedGasPlant</ID><Location><EquipmentID>SaturatedGasPlant</EquipmentID><EquipmentElementLevel>Area</EquipmentElementLevel></Location></Equipment><Equipment><ID>GasolineBlending</ID><Location><EquipmentID>GasolineBlending</EquipmentID><EquipmentElementLevel>Area</EquipmentElementLevel></Location></Equipment><EquipmentClassID>RefineryClass</EquipmentClassID><Location><EquipmentID>HoustonTx</EquipmentID><EquipmentElementLevel>Site</EquipmentElementLevel></Location></Equipment><Equipment><ID>DallasTX</ID><Description>Big Corp Dallas TX site</Description><Description>This site manufactures parts and assemblies for the Aerospace Industry</Description><Description>This is an example of a Discrete Manufacturing facility</Description><Location><EquipmentID>DallasTx</EquipmentID><EquipmentElementLevel>Site</EquipmentElementLevel></Location></Equipment></Equipment><EquipmentClass><ID>RefineryClass</ID><Description>Identifies Site type as being a refinery</Description><EquipmentClassProperty><ID>StringProp erty</ID><Description>This is a sample test property</Description><Description>This is not a real property</Description><Value><ValueString>Sample string value</ValueString><DataType>string</DataType><UnitOfMeasure>N/A</UnitOfMeasure><Any/></Value></EquipmentClassProperty><EquipmentClassProperty><ID >MultiValueStringProperty</ID><Value><ValueString>String 1</ValueString><DataType>string</DataType><UnitOfMeasure>N/A</UnitOfMeasure><Any/></Value><Value><ValueString>String 2</ValueString><DataType>string</DataType><UnitOfMeasure>N/A</UnitOfMeasure><Any/></Value><Value><ValueString>String 3</ValueString><DataType>string</DataType><UnitOfMeasure>N/A</UnitOfMeasure><Any/></Value></EquipmentClassProperty><EquipmentClassProperty><ID >NumericProperty</ID><Value><ValueString>200</ValueString><DataType>double</DataType><UnitOfMeasure>Mbbl/month</UnitOfMeasure><Any/></Value></EquipmentClassProperty></EquipmentClass></EquipmentInformation>
Nov 12 '05 #1
1 2231
"scorpion74" <an*******@discussions.microsoft.com> wrote in message news:9A**********************************@microsof t.com...
I have following xml file and I want to read <EquipmentClass> tag and it's Text.
This xml file implements B2MML schema and hence xml file structure is not the
usual one.
What's unusual about it?
Does anybody know how to ahieve the result?I tried using "SelectNodes"
method but it doesn't work.


How did you specify the namespace URI, http://www.wbf.org/xml/b2mml-v02,
in the XPath expression when you called SelectNodes( )?

This is the likely culprit, at least it's the most frequently asked about.

XmlNamespaceManager nsMan = new XmlNamespaceManager( xmlDoc.NameTable);
nsMan.AddNamespace( "ns1", "http://www.wbf.org/xml/b2mml-v02");
XmlNodeList results = xmlDoc.SelectNodes( "//ns1:EquipmentClass/ns1:ID", nsMan);
if ( null != results )
foreach ( XmlNode n in results )
Console.WriteLine( n.InnerText);

Since you can't specify a prefix for the default namespace in the XPath
expression, it needs a prefix associated with that default namespace URI
just for purposes of writing the expression. In order to evaluate the ex-
pression, it needs a reference to a Namespace Manager supplied to
the SelectNodes( ), which has an overload accepting XmlNamespace-
Manager.
Derek Harmon
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
0
by: Darren Clark | last post by:
I am trying to understand typed datasets more.... and i am stuck on a little problem I have created a type dataset called "News" this consists of 2 tables. NewsTable and NewsTypes. the news...
2
by: darrel | last post by:
I can navigate an XML file to find a particular value as such: Dim xpd As System.Xml.XPath.XPathDocument = New System.Xml.XPath.XPathDocument(XMLfile) Dim xpn As System.Xml.XPath.XPathNavigator...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
7
by: jon cosby | last post by:
This code shows all values for the config node. I'm trying to retrieve the value for systrayenabled for attrib "jon". Something wrong? sXmlPath = Application.StartupPath.ToString() +...
5
by: requeth | last post by:
I am trying to create (another) type of report and I have been beating my head against the wall for several minutes now. Here's the problem: <CMS27423400_2140CA>...
4
by: =?iso-8859-1?q?S=E9bastien_Ros?= | last post by:
I have to process the xmlns declarations in the root node of a document. Unfortunately, they are not recognized as elements nor as attributes. Even with a /root/node() I can't reach them. ...
0
by: in10se | last post by:
I have a .NET 2.0 application that uses the WebBrowser control. Because all of my pages are generated dynamically, I am catching the Navigating event, cancelling it, and performing my own operations...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.