|
Thank you all
|
|
|
|
|
I need to access the value of a node that also contains childnodes such as
<node>
text
<child>value</child>
</node>
Inner text doesn't work because I get the child text also. I think that the way Innertext is done is pretty bad. Any Ideas? Thanks.
Steve
Steve
Not all who wander are lost...
|
|
|
|
|
You can just iterate through the children (IXMLDOMNodeList) checking the type (IXMLDOMNode::nodeType), if it is a text node (NODE_TEXT) append the value to your string otherwise keep iterating...
|
|
|
|
|
Thanks. Will this also work on .NET?
Steve
Not all who wander are lost...
|
|
|
|
|
Sure, it'll work with any DOM/Language, just the interface/method/constants names may vary slightly...
|
|
|
|
|
|
I'd like to store some data from an XML file to an Oracle Database but there is a problem with several czech characters that are not stored (interpreted, shown?) properly in the database.
The way: XML file (UTF-8 charset, czech characters put into document by using XMLSpy) --> MS-VS6, SP5 C++ program (MSXML 4, import <msxml4.dll> raw_interfaces_only) --> DOM(load method, firstChild->get_text(BSTR)) --> BSTR variable --> wchar_t* --> SQLExecDirectW --> connection string including switch to enable forcing SQLWCHARs --> Oracle DB (using Oracle Driver 9.2., CZECH_CZECH REPUBLIC.EE8ISO8859P2 in registry, all Homes) --> displayed in Toad (Arial, Central European). Some characters are replaced by similar ones, some of them can't be recognized.
Please, help!
|
|
|
|
|
I see now, that Excel is showing the data properly. Toad doesn't...
|
|
|
|
|
Can anyone tell me how generate a sample XML instance from a XSD file.
|
|
|
|
|
Is there a way to specify a search root to selectSingleNode?
it always gives me the first hit in the file even if the Node that is calling the function is located after the node that gets found.
for example, in file
<forms count="2">
__
____<item>1<\Item>
__
__
____<item>2<\Item>
__
(for some reason the opening Item tags dissapear when i post)
How should I Locate Item 2(In c++) without using child or nextsibling pointers(I cant guarantee the order of the child Items)
|
|
|
|
|
Sorry but that is what selectSingleNode does, return the first node that matches the criteria. You could and the value you are looking for (2) to search string. "forms/form/2" (wrong syntax I know but you get the idea), possibly "forms/form/position() == 2" might work.
|
|
|
|
|
So does that mean there is no search function that allows you to enter a starting point to search from?
I'm not familiar with position(). Except that it is XSL and I do not have a stylesheet. Is it possible to use the XSL funtions without that?
|
|
|
|
|
Oops. I take my previous posting back . You should be able to create an XPATH with the position() function. position is an XPATH function that maybe be used in an XSLT. So you just need to create the correct XPATH. Though position is used when you are in a loop. So using it directly will not help.
Instead in your case it would be something like Forms/Form/Item[2] or Forms/Form[2]
|
|
|
|
|
Thanks. that did the job
although for the record it was /Form[2]/Item instead of /Form/Item[2]
|
|
|
|
|
does anybody know how to: bind to xml files to one datagrid
thanks
Da Intern
|
|
|
|
|
Like was said in the other forum, the schemas must match first.
|
|
|
|
|
can you bind mutiple cml files to 1 datagrid in aspx
thanks in advance
Da Intern
|
|
|
|
|
|
Hi all,
I'm trying to convert a .NET DataSet into something viewable by a webbrowser. Its trivial to get the dataSet into XML format (.WriteXML), and then I need to transform that with an XSLT transformation. The problem is, the dataset comes back as xml like this:
<br />
...<br />
<Table><br />
<OBJECT_NAME>ADD_ADZIP</OBJECT_NAME><br />
<OBJECT_ID>164116</OBJECT_ID><br />
<OBJECT_TYPE>PROCEDURE</OBJECT_TYPE><br />
<CREATED>2003-06-19T14:08:03.0000000-04:00</CREATED><br />
<LAST_DDL_TIME>2003-06-19T14:10:19.0000000-04:00</LAST_DDL_TIME><br />
<TIMESTAMP>1998-12-22:11:10:19</TIMESTAMP><br />
<STATUS>VALID</STATUS><br />
</Table><br />
<Table><br />
<OBJECT_NAME>ADD_LABEL</OBJECT_NAME><br />
<OBJECT_ID>164202</OBJECT_ID><br />
<OBJECT_TYPE>FUNCTION</OBJECT_TYPE><br />
<CREATED>2003-06-19T14:08:11.0000000-04:00</CREATED><br />
<LAST_DDL_TIME>2003-06-19T14:10:20.0000000-04:00</LAST_DDL_TIME><br />
<TIMESTAMP>1998-12-22:11:10:20</TIMESTAMP><br />
<STATUS>INVALID</STATUS><br />
</Table><br />
...<br />
Which is fine but I get lost when it comes to transforming this data with an XSLT file. The problem is I need to know the element names (OBJECT_NAME, OBJECT_ID, etc) for the html file, but I do not want to hard-code these names into my .xslt file, nor do I wish to generate one on the fly.
To give you some more background: All this app does is select some rows from a user defined table and outputs them to some files (CVS, tab delimited, and xml/html). The html is nothing fancy, I just want to dump them into a standard html table that is viewable in a browser, with field names at the top and data beneath it.
This doesnt seem like it should be too hard to do. Every example of XSLT Ive seen is very clear and straightforward, I just havent been able to find anything about grabbing an elements name, and Im not sure how to change the format of the XML given by the dataset (which would be another solution - if I just formatted the xml differently).
Any suggestions? Thanks
Dave Ratti
|
|
|
|
|
use need to use the name() function in xslt.
In order to not hard code element names you should pass them as parameters to your xslt.
so something like:
<?xml version="1.0" encoding="UTF-8" ?><br />
<xsl:stylesheet <br />
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />
version="1.0" ><br />
<br />
<xsl:param name="column_name">object_NAME</xsl:param><br />
<br />
<xsl:template match="/"><br />
<xsl:value-of select="//table/*[name() = $column_name]/text()"&/><br />
</xsl:template><br />
<br />
</xsl:stylesheet>
if you don't pass a parameter to your xslt, then it will default to 'object_NAME'.
c# calling code:
XslTransform xslt = new XslTransform();<br />
XmlDocument document = new XmlDocument();<br />
document.LoadXml(xmlFileName);<br />
xslt.Load(stylesheetFileName);<br />
<br />
MemoryStream ms = new MemoryStream();<br />
XPathNavigator nav = document.CreateNavigator();<br />
<br />
XsltArgumentList xslArg = new XsltArgumentList();<br />
<br />
xslArg.AddParam("column_name", "", "name of column you want");<br />
<br />
xslt.Transform(nav, xslArg, ms, null);<br />
<br />
StreamReader sr = new StreamReader(ms);<br />
ms.Position = 0;<br />
string result = sr.ReadToEnd();<br />
sr.Close();
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Great, thanks.
One more question - what if I dont know how many columns the table is going to have? I think I might be able to hack something together with mxlns:script, unless anyone has a better idea?
Thanks
Dave Ratti
|
|
|
|
|
as you guessed you will have to scripting to do this - version 1 of xsl is pretty bare bones...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Ok, thanks for your time; you were very helpful
Dave ratti
|
|
|
|
|
When i search a certain xml-file using "selectNodes("//ROOT/BLA")" and i receive the found nodes. Is it possible to get iterate through those found nodes and retrieve their current position in the xml-tree? (remember that this is DOM and not XSLT, so "position()" and all that crap won't work).
Any help is greatly appriciated.
|
|
|
|
|
by position I presume you mean name - you could use:
XmlNodeList results = document.SelectNodes(""
foreach (XmlNode result in rtesults)<br />
{<br />
Console.Write("found {0} value = '{1}'", GetNodeName(result), result.value);<br />
}<br />
<br />
string GetNodeName(XmlNode node)<br />
{<br />
string result = node.LocalName;<br />
<br />
if (node.Parent != null)<br />
result = GetNodeName(node.Parent) + "/" + result;<br />
<br />
return result;<br />
}
if you want the position then just change the above function to count previousSiblings:
<br />
string GetNodePosition(XmlNode node)<br />
{<br />
int previousSiblings = 0; <br />
for (XmlNode previous_node = node.PreviousSibling; previous_node != null; previous_node = previous_node.PreviousSibling)<br />
previousSiblings++;<br />
string result = previousSiblings.ToString();<br />
<br />
if (node.Parent != null)<br />
result = GetNodeName(node.Parent) + "/" + result;<br />
<br />
return result;<br />
}
hope this helps
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|