|
hi,
I can remember I had similar problem long time ago... I can't recall how I solved that one, bt why are you not using namespace prefix? It should work with it and I see no reason why not to use it...
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
The xml file is large - originally generated, and then hand-modified. I do not want to use namespace prefixes unless I have to, as
1) they will bloat the file
2) it will take a while to edit the file
my blog
|
|
|
|
|
oh now I don't even know what I meant
Try to add namespace prefix into XPath query. If it wont work say "DNH is idiot" (cuz i think there is no difference when you have namespace prefix in every element or only in parent) and look at link I provide you now;
hopefully the answer will be here[^]
I didn't read it all bt it looks promising.
Here is quite late night so I'll leave it alone for now. plz if you'll find answer post it here.. In other case I'll look at it tomorrow...
good luck,
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
I finally found something what seems to be solution...
[ snippet is from my website's rss feeder - i *think* it worked...]
<br />
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);<br />
nsmgr.AddNamespace("ns",@"http://www.w3.org/1999/xhtml");<br />
<br />
XmlNodeList newsNodes = doc.DocumentElement.SelectNodes("//ns:body/ns:form/ns:div[@class='parent']/ns:div[@class='contents']/ns:div[@class='news']",nsmgr);<br />
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Yes! Thanks, that works great.
my blog
|
|
|
|
|
i want to check for the value of xml node to be compulsory through XSD (schema file),,,
i have tried minoccurs and nillable!
Can anyone Help me out!
Be Humble in Victory and Strong in Defeat. -Het
|
|
|
|
|
Hmm and what exactly is your goal?
To allow element have no content, check
http://www.w3.org/TR/xmlschema-1/#xsi_nil[^]
"An element so labeled must be empty, but can carry attributes if permitted by the corresponding complex type."
Minoccures attribude specifies number of occurences of (child) element.
May the W3ForCe be with you.
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
thanks man!
i got the solution...
Happy New Year by the way
Be Humble in Victory and Strong in Defeat. -Het
|
|
|
|
|
Well as the W3C can always change/update the XML standards then will the applications developed based on .Net XML related classes be affected? Will there be any problem running these application later on. If yes, how can we keep our applications up to date.
|
|
|
|
|
I have a 4 X 4 matrix that represents a topologoy. suppose connected is that matrix. if connected[i,j]=1 then there is a edge between node i and node j. If connected[i,j]=0 then there is no edge. I want to encode this in XML format such that it must draw this network topology.
Any one help will be greatly appreciated.
|
|
|
|
|
hi there,
so you want to represent graph in XML... nice homework, I guess
If you want to represent that matrix, what about:
<matrix>
<row>
<col connected="1" /><col/><col/><col/>
</row>
<row>
<col/><col/><col connected="1"/><col/>
</row>
<row>
<col/><col/><col/><col/>
</row>
<row>
<col/><col/><col connected="1"/><col/>
</row>
</matrix>
My first idea and indeed far from ideal structure for this task. However I gave you some ideas hopefully.
It's, of course, too much verbose representation of your graph.
What about
<graph>
<edge start="1" end="5" />
<edge start="4" end="2" />
.
.
.
</graph> ?
There you have some representations... Think about it (do not shoot like I do!) and choose the best for u
does it help?
best regards,
David 'DNH' Nohejl
Never forget: <i>"Stay kul and happy"</i> (I.A.)
|
|
|
|
|
hi!!
i'm trying to process an xml file containing document tags & text, and skip certain blocks of the text based on condition tags. the problem i'm finding is that when i use apply-templates to move on and skip blocks of the document, it doesn't actually miss any of the text that i'm trying to avoid outputting to the resultant html document. i guess the question i have is, can you actually jump around an xml document using apply-templates?? i'm quite new to this stuff so please bear with me if i'm doing something wrong.
i've copied the code below just incase you want to see what i'm actually trying to do & run the transform for yourself. you'll need to create the following three files:
source.xml, "merge-data.xml" & test.xsl
(the file name in quotes has to have that exact name and be in the same directory as the stylesheet unless you want to change the code in the stylesheet).
source.xml:
<?xml version="1.0" encoding="UTF-8"?>
<br>
<!-- SOURCE DOCUMENT TO BE TRANSFORMED -->
<br>
<doc>
<page>
<content>
<para>
<run>
<text>
<condition eval="THIS = 'TEST'"><<IF THIS = 'TEST'>></condition>
</text>
</run>
</para>
<para>
<run>
<text>IF EVALUATED TO TRUE!!!</text>
</run>
</para>
<para>
<run>
<text>
<condition eval="ELSE"><<ELSE>><<IF THIS = 'TEST'>></condition>
</text>
</run>
</para>
<para>
<run>
<text>IF EVALUATED TO FALSE!!!</text>
</run>
</para>
<para>
<run>
<text>
<condition eval="END"><<ENDIF>><<IF THIS = 'TEST'>></condition>
</text>
</run>
</para>
</content>
</page>
</doc>
"merge-data.xml":
<?xml version="1.0" encoding="UTF-8"?>
<!-- source document's condition information (merge-data.xml) -->
<dataset>
<condition ref="<<IF WEATHER = 'BAD'>>">TRUE</condition>
<condition ref="<<IF THIS = 'TEST'>>">TRUE</condition>
<condition ref="<<IF THISDATA = 'RANDOM'>>">TRUE</condition>
</dataset>
test.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<!-- xslt stylesheet -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sdp="http://www.sectornet.co.uk/2004/DocPro">
<xsl:output method="html"/>
<xsl:variable name="mergeData" select="document('merge-data.xml')//dataset"/>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="/">
<html>
<head>
<title>condition test output.</title>
</head>
<body>
<center>
<h1>Condition Test.</h1>
</center>
<xsl:apply-templates select="doc/page/content"/>
</body>
</html>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="para">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="text">
<xsl:apply-templates/>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="condition">
<xsl:variable name="curNode" select="."/>
<xsl:text> (CONDITION) </xsl:text>
<xsl:choose>
<xsl:when test="$curNode/@eval = 'ELSE'">
<!-- process else statement -->
<xsl:variable name="prevIfNode" select="$mergeData/condition[@ref = substring-after($curNode, '<<ELSE>>')]"/>
<xsl:if test="$prevIfNode = 'TRUE'">
<!-- go to end tag -->
<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ENDIF>>', $prevIfNode/@eval)]"/>
</xsl:if>
</xsl:when>
<xsl:when test="$curNode/@eval != 'END'">
<!-- process if statement -->
<xsl:variable name="curIfNode" select="$mergeData/condition[@ref = $curNode]"/>
<xsl:if test="$curIfNode != 'TRUE'">
<xsl:choose>
<xsl:when test="ancestor::*/following::*/condition/text() = concat('<<ELSE>>', $curNode)">
<!-- go to else tag -->
<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ELSE>>', $curNode)]"/>
</xsl:when>
<xsl:otherwise>
<!-- go to end tag -->
<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ENDIF>>', $curNode)]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
thanks!!!
|
|
|
|
|
I've just realised that by changing the conditions return value from "TRUE" to "FALSE" (see merge-data.xml above), you can see it skipping the block. this is great, but after it's skipped the block it returns and continues processing from it's original position. e.g. it meets the first condition tag (if statement), then the template causes the jump to the else block because the if evaluates to false, but once that call has been completed it continues from the original condition tag (if statement). so basically the apply-templates is put on a call stack as it is in most programming languages' function calls. something i hadn't realised!! the problem is how to prevent it from continuing along nodes that i want to skip. i'm pretty sure it's down to the initial <xsl:apply-templates select="doc/page/content"/> found in the root template. it's obviously going to end up calling a template for all implemented tags under the content node. can anyone see a way to change this statement to be a bit more selective in which nodes it processes? or any other suggestions would be great!!
thanks!!
|
|
|
|
|
Just incase anyone would find this helpful, i've got it working. it's not really how i wanted it to be written, so if anyone can see a better way of doing it then please say. i've also added another special document control called a dataname (basically a variable), so by adding text to the document enclosed in <dataname> tags with a reference to that and its value in the merge-data.xml file (e.g. <dataname ref="<<CFNAME>>">RICH</dataname> then you can effectively merge data into the document. the stylsheet code is copied below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sdp="http://www.sectornet.co.uk/2004/DocPro">
<xsl:output method="html"/>
<xsl:variable name="mergeData" select="document('merge-data.xml')//docpro-print-entry/dataset"/>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="/">
<html>
<head>
<title>condition test output.</title>
</head>
<body>
<center>
<h1>Condition Test.</h1>
</center>
<xsl:apply-templates select="doc/page/content/para[1]"/>
</body>
</html>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="para">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="text">
<xsl:choose>
<xsl:when test="count(self::*/*) > 0">
<!-- we have controls in this block -->
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<!-- output text and move on to next block -->
<xsl:value-of select="."/>
<xsl:apply-templates select="ancestor::*/following-sibling::*[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="dataname">
<xsl:param name="sourceContext" select="$mergeData"/>
<xsl:variable name="curNode" select="."/>
<xsl:value-of select="$sourceContext//dataname[@ref = $curNode]"/>
<!-- move on to next block -->
<xsl:apply-templates select="ancestor::*/following-sibling::*[1]"/>
</xsl:template>
<!-- ++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++ -->
<xsl:template match="condition">
<xsl:variable name="curNode" select="."/>
<xsl:choose>
<xsl:when test="$curNode/@eval = 'ELSE'">
<!-- process else statement -->
<xsl:variable name="prevIfNode" select="$mergeData/condition[@ref = substring-after($curNode, '<<ELSE>>')]"/>
<xsl:choose>
<xsl:when test="$prevIfNode != 'TRUE'">
<!-- continue through the block -->
<xsl:apply-templates select="ancestor::*/following-sibling::*[1]"/>
</xsl:when>
<xsl:otherwise>
<!-- go to end tag -->
<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ENDIF>>', $prevIfNode/@ref)]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$curNode/@eval != 'END'">
<!-- process if statement -->
<xsl:variable name="curIfNode" select="$mergeData/condition[@ref = $curNode]"/>
<xsl:choose>
<xsl:when test="$curIfNode = 'TRUE'">
<!-- continue through the block -->
<xsl:apply-templates select="ancestor::*/following-sibling::*[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="ancestor::*/following::*/condition/text() = concat('<<ELSE>>', $curNode)">
<!-- go to else tag -->
<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ELSE>>', $curNode)]"/>
</xsl:when>
<xsl:otherwise>
<!-- go to end tag -->
<xsl:apply-templates select="ancestor::*/following::*/condition[text() = concat('<<ENDIF>>', $curNode)]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$curNode/@eval = 'END'">
<!-- continue past the block -->
<xsl:apply-templates select="ancestor::*/following-sibling::*[1]"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
I am an XML rookie and need some help. I am creating a project to poll web applications and other apps and of there is an error I want to send an email. I would like to poll the different apps listed in my XML. I want to pull back a application and its attributes. I have tried the XPathNavigator methods
with little success. Any help would be appreciated as to how to approach this problem or some good basic XML instructions. Here is the XML I created maybe I need to do it differently.
<applications xmlns="http://tempuri.org/Applications.xsd">
<application>
<name>Volunteer Email
<url>http://ftwweb02/volemail/report4.asp
<apptype>web
<databaseconnectionstring>
<database>
<emailaddresstonotify>BobSmith@texashealth.org
<fullpath>
<testtime>60000
<timeout>20000
<application>
<name>XBox App
<url>none
<apptype>database
<databaseconnectionstring>pwd=214;uid=me
<database>
<emailaddresstonotify>GeraldStanford@texashealth.org
<fullpath>
<testtime>60000
<timeout>20000
|
|
|
|
|
Hi,all
I have few issues with Xslt transfer xml to xml
1: xml is from a string, how xslt transfer a dynamcally generated string instead of a file;
2: I transfer xml to xml string by xslt, but the XML
string can't be validated by schema. the thing is that if I load the generated XML string into VS studio and save it,which become a file. it can be validated. or it is valid if I just add a blank
space anywhere.
It might be the format issue with file and string, but I think it is weired.
|
|
|
|
|
add 1) System.Xml.XsltTransform.Transform() method accepts TextWriter as an argument (see MSDN[^]). StringWriter is derived from TextWriter, so...
hi,
add 2) similarly, System.Xml.XmlValidatingReader constructor takes XmlReader as argument. Xmlreader can read from stream. and string can be written into stream (e.g System.IO.MemoryStream ).
I only made some searches at MSDN and didn't try it. Let me know if there is any problem
Does it help?
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi,David:
1. yes, you are right for the first problem. I am using a StringReader to read the string and then use the XMLtextReader to read that stringReader,
2. NO. it wasn't that issue, the issue is that the decodeing problem, I need to change it to UTF-8, then done. thanks.
|
|
|
|
|
hi,
I don't understand to your problem than. You have XML in string, right? and you want to validate it with XmlValidatingReader.. And there is problem with encoding? How you get that xml string? from file? in which encoding it is? See this MSDN[^]
which encodings are supported by XmlTextReader. If it's not your case see System.Text.Encoding etc.. sry I must go now I'll look at it later.
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
when the xml string was generated, it was UTF-16, the XmlValidatingReader can't take it. ( For some reason, but might not this issue), I just changed it by UTF-8 using String.replace, and it is working now.
thank you very much.
|
|
|
|
|
titabonbon wrote:
thank you very much
lol you bring up question, force me to look at it, than you post answer (so I learned something I didn't know before) and than you thank me! Wonderful
marry christmas!
FYI: "All the encoding standards that the underlying operating system supports are supported." MSDN[^]
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
oh, sorry.
because my project is on due, I have to do whatever I can, fortunately I solved it. but I want to thank you for your help sincerely. and I just gave you some reference maybe it can help sometime.
happy holiday.
|
|
|
|
|
titabonbon wrote:
oh, sorry.
No I didn't mean it ironic!
happy holiday to you too
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Hi,
I have one question about System.Xml.XmlAttribute class. Why it has ChildNodes property? Attributes cannot have child nodes, right? Is it bad design or did I miss something? Plz don't post answers like it's because XmlAttribute is derived from XmlNode . I know. I just don't know WHY? There is probably no case when it can be useful, since when I tried to append element to attribute (weird, I know ) it throws an exception
Unhandled Exception: System.InvalidOperationException: The specified node cannot<br />
be inserted as the valid child of this node, because the specified node is the<br />
wrong type.<br />
What is your opinion/explanation? Or give me some links to people who will answer this (.NET designers maybe?)...
Thx a lot for some ideas or suggestions!
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Readup on Abstracting base functionality into a Base implementation, together with polymorphism and you may understand why EVERYTHING in the Xml tree derives from XmlNode.
|
|
|
|