|
It's just Microsoft Windows platform, using Microsoft Visual Studio.NET 2003, ASP.NET, XML. Below is the coding part, you can amend it.
----------------------------------------------------------------------
<consult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<beginnerchoice>
<question>What is your budget?
<answer>2000-2500
<answer>2500-3000
<answer>3000-3500
<answer>3500-4000
<beginnerchoice>
<question>Are you going to watch movies on the computer?
<answer>PC games and listening music
<answer>watch movies
<answer>Web surfing, online chatting
What is your advice?
Regards,
Aaron
|
|
|
|
|
Well if the use chooses answer number 2 for the first question in the following XML...
<?xml version="1.0" encoding="utf-8" ?>
<consult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<beginnerchoice>
<question>What is your budget?</question>
<answer>2000-2500</answer>
<answer>2500-3000</answer>
<answer>3000-3500</answer>
<answer>3500-4000</answer>
</beginnerchoice>
<beginnerchoice>
<question>Are you going to watch movies on the computer?</question>
<answer>PC games and listening music</answer>
<answer>watch movies</answer>
<answer>Web surfing, online chatting</answer>
</beginnerchoice>
</consult>
Then the XPath query to extract the value that they choose would be:
//beginnerchoice[1]/answer[2]/text()
Hope that helps
-pete
|
|
|
|
|
Hi all,
How can we query xml data between two dates by using XPath.
For example:
I have an XML file like this
"<Employees>
<Employee>
<Name>xxxx</Name>
<DateOfJoin>'2000-04-12T10:12:30'</DateOfJoin>
</Employee>
<Employee>
<Name>yyyy</Name>
<DateOfJoin>'2001-04-12T10:12:30'</DateOfJoin>
</Employee>
<Employee>
<Name>zzzz</Name>
<DateOfJoin>'2002-04-12T10:12:30'</DateOfJoin>
</Employee>
<Employee>
<Name>aaaa</Name>
<DateOfJoin>'2003-04-12T10:12:30'</DateOfJoin>
</Employee>
<Employee>
<Name>bbbb</Name>
<DateOfJoin>'2004-04-12T10:12:30'</DateOfJoin>
</Employee>
</Employees>"
Now I want employee names between 2002 and 2003.
Thanks inadvance.
|
|
|
|
|
Mr/Mrs Anonymous,
According to Microsoft(moc 2663) and www.W3.org(XPath link), only nodes, node, string, bool and number items might return. So if you want to query a date you might use XmlReader or derived class. If you want it with XPath, you should do it like this.
?* If you have better idea or sth better let me know.
------------------------------------------------------
...
DateTime dt;
string name = "";
XPathExpression expression = navigator.Compile(
"/Employees/Employee/Name | /Employees/Employee/DateOfJoin");
XPathNodeIterator i = navigator.Select(expression);
while(i.MoveNext())
{
if(i.Current.Name == "DateOfJoin")
{
dt = XmlConvert.ToDateTime(i.Current.Value);
if(2002< dt.Year && dt.Year < 2004)
{
//TODO
//tbx_msg.Text += name +"\r\n";
}
}
else
{
name = i.Current.Value;
}
}
|
|
|
|
|
Try the following XPath:
<br />
/Employees/Employee[substr(DateOfJoin,0,4) <= 2003 and substr(DateOfJoin,0,4) >= 2002]/Name<br />
If you are using XSLT, it will better to select the Employee node and do with it what you please
<br />
<xsl:apply-templates select="/Employees/Employee[substr(DateOfJoin,0,4) <= 2003 and substr(DateOfJoin,0,4) >= 2002]"/><br />
<br />
<xsl:template match="Employee"><br />
<!--More Rules--><br />
</xsl:template><br />
~javier lozano
(blog || email)
|
|
|
|
|
Hi all,
How can we query xml data between two dates by using XPath.
For example:
I have an XML file like this
<employees>
<employee>
<name>xxxx
<dateofjoin>'2000-04-12T10:12:30'
<employee>
<name>yyyy
<dateofjoin>'2001-04-12T10:12:30'
<employee>
<name>zzzz
<dateofjoin>'2002-04-12T10:12:30'
<employee>
<name>aaaa
<dateofjoin>'2003-04-12T10:12:30'
<employee>
<name>bbbb
<dateofjoin>'2004-04-12T10:12:30'
Now I want employee names between 2002 and 2003.
Thanks inadvance.
|
|
|
|
|
I have two XmlDocuments. One is default settings for a new user and the other is user specific settings. I want to merge the user specific settings over the default settings while keeping all of the default settings not specified in the user specific document. I've looked at using DataSet merging but it doesn't seem like the right answer. Anyone have any ideas?
|
|
|
|
|
Dear professionals
How can be syntax coloring applied to an XML document if it is to be loaded in a rich text box for user viewing?
|
|
|
|
|
If this is just for viewing the XML then just use a IE web browser control. You'll get the sweet IE formatting of XML.
|
|
|
|
|
Besides the given answer, you may use this tag.(It is working with IE.)
<iframe src="D:\w3home\www\TestXML\xmlDocs\sam.xml" width="400" height="400" scrolling="auto" frameborder="1"></iframe>
But if you want user to modify xml doc, you should write or find JavaScript code to do it.
|
|
|
|
|
Mr.mutlugokhan
Thanks for considering my problem and responding therein. Since the user should be provided to modify the xml doc, I need some javescript to accomplish that(as per your advice). Can you help me with some such code? Or if I can get some code like this, how woul I embed it in my c# code?
|
|
|
|
|
I will examine this project later but it seems to be ok for you.
http://www.codeproject.com/aspnet/TextEditControl.asp
|
|
|
|
|
Hi,
I just inherited code at my work which creats .asmx file on the fly. To make changes don't need to compile just stop iis make changes to XML file and when iis restart and by invoking web services it generates .asmx file.
My task was to add a method to that web service. I am able to see all my changes in web services ... logic is in store procedures that passed along with the other two required parameters.
I can invoke any other method from the webservice but the one I just created.. I can see the method description their... nothing is different in .asmx .... It asks for the parameters but when I invoke its gives me authentication fail error.
One more thing is... it's using SQLXML .... I m thinking t has to do with some sqlxml rights... but have no idea ... I m struggling from last 2 days... please.. Any help.. Any idea .. any suggestion are appreciated ...
thanks
|
|
|
|
|
What's the authentication error you are receiving? Also, could you show me a sample of the code?
Thanks!
~Javier
"I don't suffer from insanity, I enjoy every minute of it." -- Unknown
|
|
|
|
|
<employees xmlns="http://www.x.com">
<employee>
<fname>x<lname>y
when i run this line
XmlNode node = doc.SelectSingleNode("/employees/employee[lname='y']/fname");
node obj is null and it made me sick because XPath expr is right..
But, if i clear below part from xml doc, query runs properly.
xmlns="http://www.x.com"
What is wrong?
Any idea..
GMtl
|
|
|
|
|
Is the XML doc available on a Web site so we can see access it?
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I found my mistake. I didnot write xpath expr correctly.
private string FindNode(string expr)
{
//load xml doc
doc.Load(rootPath + "sam.xml");
//specify default namespace
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("x", "http://www.GMtl.com");
//xpath expression
string xpath_expr = "/x:employees/x:employee[x:lname='y']/x:fname";
//get to node and read inner text
XmlNode x = doc.SelectSingleNode(xpath_expr, nsmgr);
string retval = x.InnerText;
return str;
}
-------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<employees xmlns='http://www.xy.com'>
<employee>
<fname> x </fname>
<lname> y </name>
</employee>
</employees>
|
|
|
|
|
Don't you just need to change [lname='y'] to [@lname='y'] ?
|
|
|
|
|
No, I do not. Because lname is not an atribute. The code given with my previous message was correct and it is working. In short, if you have xml doc with namespace, define namespace in code and then specify namespace in the XPath expression.
|
|
|
|
|
Can any one help I reading it a XMLstring form a web service, it read in as a XmlElement.
The Xmlstring is a dataset, How can I get the XmlString in the XmlElement in to a dataset
|
|
|
|
|
DataSet.ReadXml(XmlElement.InnerText)
|
|
|
|
|
Use an System.Xml.XmlNodeReader to read the data into the set
Example:
XmlNodeReader reader = new XmlNodeReader(<xmlelementobject>);
DataSet ds = new DataSet();
ds.ReadXml(reader);
reader.Close();
This should work!
~Javier
"I don't suffer from insanity, I enjoy every minute of it." -- Unknown
|
|
|
|
|
hi all,
i want to convert a word doc to xml format. does anyone have
any advice or code snippets to help me get started.
TIA
CocciaStella
|
|
|
|
|
hi,
At first I did not understand what you had asked, but after a quick search I have come accross these two links. I hope they would be helpful for you.
http://www.msdn.microsoft.com/office/understanding/word/codesamples/default.aspx?pull=/library/en-us/dnword2k/html/odc_expwordtoxml.asp
http://www.msdn.microsoft.com/office/understanding/word/codesamples/default.aspx?pull=/library/en-us/odc_vsto2003_ta/html/wordobject.asp
By the way I saw a site which gives demo project but I cant remember now. It deserves to be examined. Search it. (If I could remember the name, I will let you know)
|
|
|
|
|
when i updat the dataset from he emulator even though i use the writeXml it still doesnt change the actual xml file on my hard disk......as in: it doesnt save the changes made while the emulator is running.
any ideas how it can be done?
|
|
|
|