<meaning>abc<type>xyz</type></meaning>
when i use
node.innertext
it concatenates abc and xyz both how can i retrive only the innertext of meaning tag.. i.e abc only
Please don't write URGENT in the title of your post. It's actually less likely to get answered that way.
To answer your question though, there are technically two child nodes of the <meaning> node. The first child is a text node, the second is the <type> element. Instead of using node.InnerText, get the first child node and get the InnerText of that: node.FirstChild.InnerText. You also will have to be careful about whitespace in these situations.
Logifusion[^]
If not entertaining, write your Congressman.
Input XML file: http://distribution.customradionews.net/Forecast_XML/WKKI.xml
Background: I'm working to interpret information from the National Weather Service's National Digital Forecast Database. There are a number places I've found that make use of the Web Srvice offered by the NWS for this data. For reasons of capacity, I am directly downloading the NDFD data and generating my own XML files. So, I end up with a series of xml files, 1 for each station we serve.
I want to parse that file into a string array, such that the forecast for each 12 hours is in one line. An example of what one data line should look like, using the file as it stands at 12:55pm CDT 8/17/06:
(Note: in order to get sample values for the conditions, I had to go to a day other than today in the raw data. Null values are acceptable in any of the fields after Temp)
I don't have any sample code, because I'm having a hard time wrapping my mind around how to get the data from one form to another. Why, I'm not sure. I have a feeling that once someone gets me started in the right direction, I'll be able to take it form there.
Not sure what you are asking for but here is how I interpret the XML.
All the "value" type elements (temperature, cloud-amount, weather) use a time-layout attribute to reference the [layout-key] element value that they map to. After you have the corrosponding parent element there is a one-to-one child element association.
I guess what I'm having difficulty wrapping my mind around is what type of loop I need to build to parse the code.
For instance, should I step through the period-names, using them to build element two of each record in the array, then step through the valid times, throwing them into element three, and so forth -- or should I execute 1 loop. I guess what's causing the disconnect for me is how I match (for instance) the third item in the "Daily Minimum Temperature" group with the third item in the second "time-layout" group, so I end up with a low for Saturday of 63 degrees.
I'm still enough of a noob that the code to make that matchup isn't clear to me. If someone can code a snippet that will make that matchup and output the strings "Satruday night" and "63", I'll be able to take it from there.
Thanks for your response...it helped me define the problem better, anyway1
Private Sub Button_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles btnWKKI.Click, btnWWWC.Click
Dim strStation As String = sender.Text
Dim xDocument As New XmlDocument()
xDocument.Load("http://distribution.customradionews.net/Forecast_XML/" & strStation & ".xml")
Dim xpPeriod As String = "//dwml/data/time-layout[2]/start-valid-time[3]/@period-name"
Dim xpTemp As String = "//dwml/data/parameters/temperature[2]/value[3]/text()"
Dim nTemp As XmlText = xDocument.SelectSingleNode(xpTemp)
Dim nPeriod As XmlAttribute = xDocument.SelectSingleNode(xpPeriod)
Dim nlPeriod As XmlNodeList = xDocument.SelectNodes("//dwml/data/time-layout[2]/start-valid-time/@period-name")
Dim nlTemp As XmlNodeList = xDocument.SelectNodes("//dwml/data/parameters/temperature[2]/value/text()")
Dim n As Integer = 0
While n < nlPeriod.Count
Console.WriteLine("{0} - {1}", (nlPeriod.Item(n) as XmlAttribute).Value, (nlTemp.Item(n) as XmlText).Value)
n += 1
End While
End Sub
However, the IDE gives "Expression Does Not Produce A Value" on Console.WriteLine("{0} - {1}", (nlPeriod.Item(n) as XmlAttribute)...the second part of the statement is okay. What did I miss?
I'm using an XPath statement ("XPath="gpx/trk/trkseg/trkpt") to bind all the trkpt elements to my data source. My goal is to return a page that displays all of the ELE data points, and numbers them according to their position in the XML file. It should read something like this:
ele = 85, position = 1
ele = 84, position = 2
ele = 82, position = 3
My DataList control correctly identifies all of the 'ele' elements using this syntax <%# XPath("ele") %>, however I have not be able to figure out how to find the position within my dataset. Using <%# XPath("position()") %> always returns 1, and everything else I have tried either returns the same number or throughs an exception. Can anyone clue me in as to what black magic is required to have XPath (I'm assuming its XPath) return its location within a series of identical elements?
There's nothing really black magic about it. The position() function really depends on context. It will return the position of the node currently being processed. It's hard to tell what you're doing from what's given. Can you post some of the code you're working on?
Logifusion[^]
If not entertaining, write your Congressman.
You can see this code being run here = http://www.loc8r.com/steve/test8.aspx
And you can see my XML file here = http://www.loc8r.com/steve/crashminus1.xml
I assumed that position() acted as you described, and if that were the case I'd suspect that the logic would be like this.
1. The ItemTemplate repeater class sets the context to the 1st TRKPT xml element. Position() should return 1.
2. The ItemTemplate repeater class increments the context to the 2nd TRKPT xml element. Position() should return 2.
3. The ItemTemplate repeater class increments the context to the 3rd TRKPT xml element. Position() should return 3.
As I mentioned position() is always returning "1", although "ele" is correctly displaying the 3 different values within the 3 different elements.
It's quite possible that position may not be at all effective when being used in this way. Take a look at this snippet:
string s = @"
<root>
<child>a</child>
<child>b</child>
<child>c</child>
</root>
";
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNodeList nl = doc.SelectNodes("//child");
foreach (XmlNode n in nl)
Console.WriteLine(n.CreateNavigator().Evaluate("position()"));
This will print out all 1's as well. I imagine that behind the scenes, a very similar process is happening to execute your XPath statements. So far, I have been unable to come up with an alternative XPath that will work. You may want to do this another way.
Logifusion[^]
If not entertaining, write your Congressman.
MSXML2::IXMLDOMDocument2Ptr pNewDocument;
pNewDocument.CreateInstance(__uuidof(MSXML2::DOMDocument));
//load the xml file
pNewDocument->load(_bstr_t("Infor.xml"));
MSXML2::IXMLDOMNodeListPtr pNodeList;
//get he sub node "Root/SubNode"
pNodeList = pNewDocument->selectNodes(_bstr_t("Root/SubNode"));
cout<<"The new Node length is "<<pNodeList->Getlength()<<endl;
With MSXML6, I change the "__uuidof(MSXML2::DOMDocument)" to "__uuidof(MSXML2::DOMDocument40)" or "__uuidof(MSXML2::DOMDocument60)". Then the codes above can't work.
I searched the help file os msxml6 and found that the GUIDS are related the version of MSXML. The table can be like this:
ProgID Version
MSXML2::DOMDocument msxml3.dll
MSXML2:: DOMDocument40 msxml4.dll
MSXML2::DOMDocument60 msxml6.dll
With MSXML6. Should I need to replace the "__uuidof(MSXML2::DOMDocument)" wihe "__uuidof(MSXML2::DOMDocument60)"?
All kinds of ways. Search for the node that is before or after the position you want to insert your new node and use InsertBefore or InsertAfter respectively on the parent node. That's if you have an XmlDocument object open. Another way is to just insert the node at the end and apply a stylesheet. The xsl:for-each can have a child element xsl:sort that can sort your nodes in alphabetical order.
Logifusion[^]
If not entertaining, write your Congressman.
I have a page with data retrieving from user:
Name, landline no, Question to ask and Timings..Once i click on button of this page, say callback.aspx, it will generate a xml file automatically with a file name userinfo.xml
Now i try to read this file in another .aspx page say read.aspx from userinfo.xml...Everything is working fine..except for..
If another user enters info in callback and submits. And when i check it from read.aspx or userinfo.xml the previous data is lost and the new data is written...Is there any possibility that dynamically data can be appended to userinfo.xml
Please help..the following is the code in callback.aspx
string xmlFile = Server.MapPath("userInfo.xml");
XmlTextWriter writer = new XmlTextWriter(xmlFile, Encoding.UTF8);
//start writing
writer.WriteStartDocument();
writer.WriteComment("Posted on @" + DateTime.Now.ToString());
writer.WriteStartElement("UI");
//creating the <browserinfo> element
writer.WriteElementString("name", sname);
writer.WriteElementString("landline",slandline);
writer.WriteElementString("question",squestion);
writer.WriteElementString("time",stime);
writer.WriteElementString("Date",DateTime.Now.ToString());
writer.WriteEndElement();
writer.WriteEndDocument();
Well, you've got a few problems to deal with here. First of all is this line:
lehya wrote:
XmlTextWriter writer = new XmlTextWriter(xmlFile, Encoding.UTF8);
This is a shortcut to remove some of the tedium of opening a file. But, its assumption is that you want to erase the old file if one is there, not append to it.
The second problem is that you're dealing with an XML file. You can't just append to the end of the file. You have to add your new elements as a part of the existing document.
Appending to the end of an XML document is not easy. You have some options though. Open the XML in an XmlDocument object and just append your child nodes in there where appropriate, then save the file. If the XML file is big, this will take up lots of memory and be slow. Another option is to open up the existing file with an XmlReader and open up a temporary file with an XmlWriter. Read the existing XML until you get to the end of the document and while you're doing it, write those elements out to the writer. Before writing the EndDocument, write in your new elements. Then delete the old file and rename the temp file to the correct filename.
Logifusion[^]
If not entertaining, write your Congressman.
Thanks buddy...Sounds like it works..But reading everything and writing into a temporary file...saving it as a new file..oh this sounds too hard..but i will try
You could also write to a MemoryStream so long as the XML is not too big. The MemoryStream will have a smaller memory footprint than the XmlDocument object.
Logifusion[^]
If not entertaining, write your Congressman.
First check whether the xml file exists, If not create xml [ u have done this], if exists load xml file, get the root node element and append every node you add as as child node [plz don`t use processing instructions while appending to xml] and save the xml.
I have a series of tables in MS Access 2003 and would like to export a subset of the data out in an XML format.
I have come accross the Application.ExportXML facility in MS Access 2003, but is this applicable if I need to export 2 fields from Table A, 3 from Table B and 1 from Table C.
My question is, should I write a VBA module to export the data I require or are they an example on how to use Application.ExportXML in the way required.
I cant find much documentation on this facility.
Sorry if this is the wrong forum.
Many thanks
Last Visit: 31-Dec-99 18:00 Last Update: 23-Sep-24 17:13