|
hi,
i have the the Xml file that has lots of tags and I am intrested in retrieving the data in the first <id> tag.I used the XmlDataDocument class and the used the SelectSingleNode("//ID").
the whole code looks like this
StreamReader st= new StreamReader("c:\\temp\\abc.xml");
string xml=st.ReadToEnd();
XmlDataDocument xmlDoc=new XmlDataDocument();
xmlDoc.LoadXml(xml);
XmlNode xn=xmlDoc.SelectSingleNode("//ID");
Console.WriteLine("the value of the book is:"+xn.InnerText);
It gives me an runtime error can any one ishhelp in this.
Thanking you in advance.
Satish
|
|
|
|
|
Use the XmlDocument object instead of XmlDataDocument . Why? Well, XmlDataDocument is meant to be used in conjunction with a DataSet . It has extra functionality that you might not need.
On to the problem, do you know the name of the root element? The expression "//ID" searches all the document as compared to "/root/ID" or "root/ID" that searches under the first <root> element.
What kind of runtime error are you getting?
~Javier Lozano
|
|
|
|
|
hi Javier,
I am using XmlDocument and the code something like this
XmlDataDocument xmlDoc=new XmlDataDocument();
xmlDoc.LoadXml(xml);
XmlNode xn=xmlDoc.SelectSingleNode("//ID");
Console.WriteLine("the value of the book is:"+xn.InnerText);
and the Xml file is some thing like this
<FAX>
<JOBID>1625603</JOBID>
<JOBNAME>Out1</JOBNAME>
<JOBSUBMITDATE>7/8/2005 4:27:03 PM</JOBSUBMITDATE>
<STATUS>
<ID>-1</ID>
<DESCRIPTION> Successfully Queued</DESCRIPTION>
</STATUS>
</FAX>
Actually this this Xml is part of the SOAP response so there are few more tags up and down but I need Only the <ID> and <Description> out if it
My questions are
1)Shall I filter the SOAP then process the XMl or Shall I directly send the SOAP response to the XMLDocument.Which is advisable.
2)I tried to parse the SOAP response(because it is also Xml) with XML Document and tried to retrieve the <ID> value as shown above.I am getting the runtime error.
Kindly suggest me so way for this.
Thanking you,
Satish.
|
|
|
|
|
satishrg wrote:
1)Shall I filter the SOAP then process the XMl or Shall I directly send the SOAP response to the XMLDocument.Which is advisable.
How are you getting the SOAP response? If the data is small, then just send it to the XmlDocument
satishrg wrote:
2)I tried to parse the SOAP response(because it is also Xml) with XML Document and tried to retrieve the <ID> value as shown above.I am getting the runtime error.
What's the runtime error?
----------------------------
If you're just getting the data for the <Fax> element, then your XPath expression should be more descriptive. In other words, instead of "//ID", have it be (using the above schema) "FAX/STATUS". This will return the <STATUS> element and you can then access its children using the DOM.
Here's what I mean:
string xml = @"<FAX>
<JOBID>1625603</JOBID>
<JOBNAME>Out1</JOBNAME>
<JOBSUBMITDATE>7/8/2005 4:27:03 PM</JOBSUBMITDATE>
<STATUS>
<ID>-1</ID>
<DESCRIPTION> Successfully Queued</DESCRIPTION>
</STATUS>
</FAX>";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode xn = xmlDoc.SelectSingleNode("FAX/STATUS");
if (xn != null)
{
Console.WriteLine("ID: {0}\nDescription: {1}", xn["ID"], xn["DESCRIPTION"]);
}
~Javier Lozano
|
|
|
|
|
hi javier,
Thank you for the help.As I told you I am getting the SOAP response and it is not a big response but small So as you suggested I will use the XMLDocument class for this then in that case how do I give th Xpath for the SAOP does it look like this.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode xn = xmlDoc.SelectSingleNode("Soap/FAX/STATUS");
if (xn != null)
{
Console.WriteLine("ID: {0}\nDescription: {1}", xn["ID"], xn["DESCRIPTION"]);
}
Thanking you,
Satish.
|
|
|
|
|
Javier Lozano wrote:
Use the XmlDocument object instead of XmlDataDocument
Or maybe XPathDocument , if he needs only retrieve data... for exactly same reasons as you said about XmlDataDocument .
David
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
hi david,
Thank you for the help.As I told you I am getting the SOAP response and it is not a big response but small So as you suggested I will use the XMLDocument class for this then in that case how do I give th Xpath for the SAOP does it look like this.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode xn = xmlDoc.SelectSingleNode("Soap/FAX/STATUS");
if (xn != null)
{
Console.WriteLine("ID: {0}\nDescription: {1}", xn["ID"], xn["DESCRIPTION"]);
}
Thanking you,
Satish.
|
|
|
|
|
I want to make an excel program using xml and recently I read Microsoft Office 2003 references schema, but I didn't understand and when I tried the method from the book, it won't work. Can somebody tell me another source or links to learn how to make excel file using xml. Or can somebody give me some example how to do it?
|
|
|
|
|
I'm fairly new to web services, an I've run into a little difficulty that I haven't been able to find a solution for.
I need to write a web service that is basically public XmlDocument MyService(XmlDocument parameter) {...} .
The request and response XmlDocuments each need to conform to specific previously-existing XSD schema definitions.
Is there a way that I can set up a WebMethod to use an XSD file to define the content requirements of the parameter? (And likewise use yet another XSD file to define the return value?)
Grim (aka Toby) MCDBA, MCSD, MCP+SB
SELECT * FROM users WHERE clue IS NOT NULL
GO
(0 row(s) affected)
|
|
|
|
|
Just a quick question, why are you using XmlDocument as a data transport?
~Javier Lozano
|
|
|
|
|
Because it's a B2B interface, and the specification I'm working from specifies an XML schema that the input parameter and return value have to comply with.
Since the remote client will be sending XML, and I'll have to return XML, and I use XML internally in the service, there's really not much point to converting the data from XML into some artificial object model, just to convert it back to XML.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
SELECT * FROM users WHERE clue IS NOT NULL
GO
(0 row(s) affected)
|
|
|
|
|
Hi.
I'm using the GetListItems method in the List web service for sharepoint to pull a sharepoint list into an infopath document. I have that part of the code working, but how do I get the data to infopath itself?
-- Steve
|
|
|
|
|
Hi,
My requirements are that, I need to create an XML file containing data which I would retrieve from database.
What would be the best possible approach for such a problem ?
Which parsers should I opt for if I use Java as my programming language ?
Thanks and Regards,
Abdul Qadir
|
|
|
|
|
What kind of database? Can it export data as XML (e.g MSSQL can)? Is there any reason why not to use standard Java classes (JAXP) for working with XML? (link here[^])
David
|
|
|
|
|
Hi David,
The database is Oracle 9i. The values in the XML tags are the field values from database. So there are two tasks : 1) Retrieving values from database 2) Write a XML validating against a schema.
Will I be able to validate against a schema while writing a XML using JAXP?
Thanks and Regards,
Abdul Qadir
|
|
|
|
|
Hi people,
i have to change my html-form tags to xform tags in my xsl-file. i have added the xform namespace and changed the html-tags to xform-tags. and added <object id="FormsPlayer".. like in xhtml. but after transforming i dont get the form. i really couldn't find anything about it on the web. it is always about xhtml. can any body give me a link or a tip to begin??
i am sending now the original version with html-form.
thanx in advance
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/2002/06/xhtml2">
<xsl:param name="format"></xsl:param>
<xsl:param name="e_anfang"></xsl:param>
<xsl:param name="e_anzahl"></xsl:param>
<xsl:template match="page">
<html>
<head><title>Cocoon - MA.BS.KY.CK</title></head>
<body bgcolor="#CCFFFF">
<h1 align="center" style="font-family:arial; font-size:30pt; color:#000066 ">Cocoon Projekt - Gruppe MA.BS.KY.CK</h1>
<xsl:apply-templates/>
<div style="text-align:left; padding:20px; margin:25px; position:relative; left ; top ;background-color:#BDEDFF;
position:relative; left ; top ;height:100; width:%100;border:thin solid lightblue;">
<p style="position: absolute; left ; top ;font-size:23pt; font-weight:bold; color:darkblue;font-family:arial;font-style:italic">Tagebuch</p>
<br></br><br></br><br></br>
<div style="background-color:#B4CFEC">
<br></br>
<p id="t2">2- Welches Übungsblatt wollen Sie sehen?</p>
<form action="ausgabe">
<select name="e_anfang">
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
</select>
<select name="format">
<option>pdf</option><option>html</option>
</select>
<input name="e_anzahl" type="hidden" value="1"></input>
<input type="submit" value="OK"></input>
</form>
<br></br>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
Hi can someone please help
I have a XML and XSD file. My XML file holds three tables. 1 table holds the main data and the other two are used for lookups.
I want to display the data from the XML file in a grid, having used the lookup table to reslove descriptions.
this is my XML file
<newdataset>
<analysis>
<id>2
<description>test desc
<station>
<id>0
<description>All Listening
<analysis_id>2
<station_id>0
<demographic_id>1
<sweep_id>2004Q1
<value>99.9
<demographics>
<id>1
<description>old people
I would like to use VB.Net. I would also like to do some seltion on the XML file to selcct certain data such as demographic ID etc.
has anybody else done this?
|
|
|
|
|
Hi kiterjohnso
Assuming you're outputting HTML, this XSL should do the transformation you're after. Then you can use the ASP.NET XML web control to perform the XSLT transformation on the XML file server side.
<?xml version = "1.0"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "NewDataSet">
<table border = "2">
<xsl:for-each select = "Data">
<xsl:variable name = "Analysis_ID">
<xsl:value-of select = "Analysis_ID"/>
</xsl:variable>
<xsl:variable name = "Station_ID">
<xsl:value-of select = "Station_ID"/>
</xsl:variable>
<xsl:variable name = "Demographic_ID">
<xsl:value-of select = "Demographic_ID"/>
</xsl:variable>
<tr>
<td>
<xsl:value-of select = "../Analysis[ID =
$Analysis_ID]/Description"/>
</td>
<td>
<xsl:value-of select = "../Station[ID =
$Station_ID]/Description"/>
</td>
<td>
<xsl:value-of select = "../Demographics[ID =
$Demographic_ID]/Description"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
I think you may want individual records in your XML file though, e.g.
<Demographics>
<Demographic />
<Demographic />
<Demographic />
</Demographics>
Otherwise, I don't see how the XPath can distinguish between multiple Demographic, Section and Analysis table rows.
|
|
|
|
|
Hi toujin,
Thanks for this.
I am actually trying to develop a window app in VB.net. I was hoping to use a grid control.
My XML file is as below (my previous attemp went a bit wrong!)
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Analysis>
<ID>2</ID>
<Description>test desc</Description>
</Analysis>
<Station>
<ID>0</ID>
<Description>All Listening</Description>
</Station>
<Data>
<Analysis_ID>2</Analysis_ID>
<Station_ID>0</Station_ID>
<Demographic_ID>1</Demographic_ID>
<Sweep_ID>2004Q1</Sweep_ID>
<Value>99.9</Value>
</Data>
<Demographics>
<ID>1</ID>
<Description>old people</Description>
</Demographics>
</NewDataSet>
I would like to join these tables (or nodes?) to each other as you would with relational tables.
Is this possible or am i trying to use XML files for something it is not able to do.
Many thanks for your help
|
|
|
|
|
hi,
I need to get only the values of 2 nodes in the whole XML document and Even if the nodes are repeated in the XML document I need to get only the first nodes value.
Can any one suggest how to do this with the sample code.
Thanks in advance,
Satish.
|
|
|
|
|
OK, I'll try. Use Sytem.Xml.XmlTextReader for this.
This is only example, since I don't know what nodes you want to read or how your XML file looks like.
int i = 0;
while( reader.Read() && i<2)
{
if( reader.NodeType == XmlNodeType.Element)
{
i++;
node1 = reader.InnerXml;
}
}
Does it help?
David
|
|
|
|
|
I want to make a chatting application using web services. Ne1 have an idea on how to do this?
Ur contribution is extremely valuable
|
|
|
|
|
Hi all,
I have a .xml file that looks similar to this,
<real_time_data_screen>
<screen_title>
<english>Screen Title</english>
<alternate_language>xzScreen xzTitle</alternate_language>
</screen_title>
<screen_classification>4294967295</screen_classification>
<screen_group>256</screen_group>
<guage_configuration>
<name>
<english>Guage Name</english>
<alternate_language>xzGuage xzName</alternate_language>
</name>
<guage_id>2</guage_id>
<units>
<english>Units</english>
<alternate_language>xzUnits</alternate_language>
</units>
<minimum>1</minimum>
<maximum>10</maximum>
<sections>
<number>10</number>
<limits>10</limits>
<color>234</color>
</sections>
</guage_configuration>
<analogue_variable>
<name>
<english>Variable Name</english>
<alternate_language>xzVariable xzName</alternate_language>
</name>
<input_values>
<minimum>1</minimum>
<maximum>10</maximum>
</input_values>
<output_values>
<minimum>1</minimum>
<maximum>10</maximum>
</output_values>
<needle_color>234</needle_color>
<guage_id>2</guage_id>
</analogue_variable>
<digital_led>
<name>
<english>LED Name</english>
<alternate_language>xzLED xzName</alternate_language>
</name>
<variable_id>2</variable_id>
<clear_color>255</clear_color>
<set_color>0</set_color>
</digital_led>
</real_time_data_screen>
I need to read through this file and create objects and update attributes depending on the data in this file. The objects will be screen, gauge, analogue and digitalLed. I've got very basic knowledge of xml and can just about read through the file and get elements and the corresponding value. How would I best go about reading throuh the file and when I find a screen tag (for instance) create a screen object and anything within that tag be written to the object.
Hope this makes sense and thanks in advance.
|
|
|
|
|
Not any ideas???
|
|
|
|
|
you may want to have a look at serialization check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexxml/html/xml01202003.asp[^]
or maybe do a search on google for serialization. I think (not sure here) but you need to have an object already defined before you can deserialize xml to it.
Another way (and im not sure if it is a good way) would be to go through the xml similar to this way:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.load(xmlSource);
XmlNode screenNode = doc.documentElement.selectSingleNode("//real_time_data_screen")
now you have your screen portion of the xml and you can use that node to select whatever you want from the screen section e.g.
screenNode.selectSingleNode("//screen_title")
Something like that I anyways.
|
|
|
|