473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to search for a specific tag in XML using C# [ Microsoft Infopath]

I'm a web application student and I'm working to solve an issue pulling in some tags from different XML documents for an Info Path Project I'm working on for a client.

I'm trying to pull in
Expand|Select|Wrap|Line Numbers
  1. <tagX>123</tagX>
but in my code there's many "TagX"s and I need to pick a specific one.

The way I'm supposed to find it is direct my program to pull that specific one based on what is encased in.


I want look inside
Expand|Select|Wrap|Line Numbers
  1.  <Casing3></Casing3>
to get my tag.


Basically it looks something like this:

Expand|Select|Wrap|Line Numbers
  1. <Casing1>
  2.  <TagX>
  3.    FALSE
  4.  </TagX>
  5. <Casing1>
  6.  
  7. *lines and lines of code*
  8.  
  9. <Casing2>
  10.  <TagX>
  11.    FALSE
  12.  </TagX>
  13. </Casing2>
  14.  
  15. *lines and lines of code*
  16.  
  17. <Casing3>
  18.  <TagX>
  19.    123
  20.  </TagX>
  21. </Casing3>
  22.  
  23.  

I need to point it to "Casing3" specifically.
I can't just use a continue statement to skip the first two, because there could be none or their could be 7 other "casings" before the "Casing3" in these different XML files.

I'm pulling in other tags that only occur once, and this is what the code looks like for them (this is just a segment of the working code. It's not clean or perfect, but so far it works)


Expand|Select|Wrap|Line Numbers
  1.   {
  2.             XPathNavigator mainDSNav = MainDataSource.CreateNavigator();
  3.  
  4.             string s = mainDSNav.SelectSingleNode("/my:myFields/my:XMLFile", NamespaceManager).Value; //reads xml file
  5.  
  6.             if (s == "")
  7.             {
  8.             }
  9.             else
  10.             {
  11.                 string result = Encoding.ASCII.GetString(InfoPathAttachmentDecoder(s));
  12.                 XmlDocument doc = new XmlDocument();
  13.                 doc.LoadXml(result);
  14.                 XmlNodeList list = doc.GetElementsByTagName("CAT");  //gets node "CAT" from the XML file
  15.                 XmlNodeList list2 = doc.GetElementsByTagName("DOG"); //gets node "DOG" from the XML file
  16.  
  17.                 foreach (XmlNode node in list)
  18.                 {
  19.                     mainDSNav.SelectSingleNode("/my:myFields/my:catText", NamespaceManager).InnerXml += node.InnerText; //sends the value encased in node "CAT" to the "catText" field
  20.                 }
  21.                 foreach (XmlNode node in list2)
  22.                 {
  23.                     mainDSNav.SelectSingleNode("/my:myFields/my:dogText", NamespaceManager).InnerXml += node.InnerText; //sends the value encased in node "DOG" to the "dogText" field
  24.                 }
  25.  
  26.             }
  27.  
  28.         }
  29.  
***tag names were edited to protect my client***

Any ideas?

(and if I'm using terms wrong, I apologize. This is my first project working with XML, so I'm learning as I go)
Jul 7 '10 #1
1 3771
jkmyoung
2,057 Expert 2GB
SelectSingleNode("//Casing3/TagX")
Jul 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sven Steinacker | last post by:
Hi, XSLT files generated by Microsoft InfoPath applied to an applicable XML file produces quite decent HTML presentations. At least with Mozilla and, of course, IE 6.0 the results look the same...
0
by: Aamir79 | last post by:
Hi all, I'm using Microsoft Applications cache block in my web application. It worked fine for sometime then suddenly it is raising the following error: Message: "Can't validate the current...
1
by: Tom Kearney | last post by:
Hi - I'm trying to use "Microsoft.VisualBasic.Logging.FileLogTraceListener" from a set of C# aspx web pages, but I can't seem to use: <%@ Import Namespace="Microsoft.VisualBasic.Logging" %> I...
1
by: Casey | last post by:
Hi, How would one allow for possible multiple search criteria using FREETEXTTABLE. For example, my table "listings" has a full-text search catalog, and I may want to: SELECT * FROM listings...
3
by: cybose | last post by:
Can someone help me write a HelloWorld dll using Microsoft's C++ compiler. It was straightforward doing it on Cygwin/g++, but it seems to be an entirely different story on the MS C++ ? In the...
1
by: akjal | last post by:
Hi friends, I have a requirement to convert a Microsoft infopath form(.xsn file) to pdf file in windows application. Can anybody an suggest a solution for this. It's very very urgent ,...
0
by: frederick.the.fool | last post by:
I'm writing a project that does Visio automation. I'm writing it in C+ +/CLI because it needs to reference a good amount of native C++ code. One way to call the Visio API, of course, is to use...
1
by: abhilash12 | last post by:
hai how can i search word using java from open office og doc file pls help me
4
by: kinannawaz | last post by:
I have been given a project to build a search engine using c++ i am enrolled in data structure course. I want to convert an html file into a .txt file than i have to search the page with the string...
0
livid86
by: livid86 | last post by:
Hello, I'm trying to create a simple test project that will read and write from a SQL CE database. I have written a small amount of code and getting weird errors that i have googled and do not...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.