f

#### XPath for non-empty #text nodes (tDOM)

Hello!

What's would be the syntax for a query, which would allow me to get only the
elements with non-empty text-nodes?

For example, from:

<a><b></b></a>
<c/>
<d><e>meow</e></d>

I only want to get the d/e ... If this matters, I'm using Tcl with the tDOM
extension. Thanks!

-mi


 0
mill (61)
4/9/2008 8:45:47 PM
comp.text.xml 8781 articles. 0 followers.

14 Replies
560 Views

Similar Articles

[PageSpeed] 21

In article <44qdncuBAoFht2DanZ2dnUVZ_s-pnZ2d@speakeasy.net>,
Mikhail Teterin  <usenet+mill@aldan.algebra.com> wrote:

>What's would be the syntax for a query, which would allow me to get only the
>elements with non-empty text-nodes?

Presumably you mean direct text children (rather than descendants),
and by "non-empty" you mean "containing something other than whitespace".

If so, try

*[normalize-space(text()) != ""]

(or with // at the start, depending on the context).

-- Richard
--
:wq

 0
richard91 (3692)
4/9/2008 8:55:42 PM
Richard Tobin wrote:
> Presumably you mean direct text children (rather than descendants),
> and by "non-empty" you mean "containing something other than whitespace".
>
> If so, try
>
> *[normalize-space(text()) != ""]
>
> (or with // at the start, depending on the context).

Yep, that worked, believe it or not. Thank you very much for the quick
response!

Yours,

-mi

 0
mill (61)
4/9/2008 8:58:20 PM
Hello!

I need to locate all nodes named "mp:date". For some reason, the

$xml selectNodes {//mp:date} does not find any, but$xml selectNodes {//*[name()="mp:date"]}

works. What's the reason for the difference? xml_grep (Perl's front-end to
XPath) find the right things with just "//mp:date".

Of these nodes, I, actually, only need the ones, where an attribute
"xc:value" is not "TODAY". How do I express this?

Thanks a lot!

-mi


 0
mill (61)
5/2/2008 7:58:03 PM
Hello!

I need a rule, that will check a certain attribute (xc:value) of all nodes
against /several/ different values...

The following syntax:

$txml selectNodes {//*[@xc:value!="FOO" and @xc:value!="BAR"} does not generate syntax errors, but does not return anything either... I tried it with and without the xc:-prefix... What am I doing wrong? Thank you! -mi   0 mill (61) 5/2/2008 8:28:18 PM In article <0MadnUIyWvj-5IbVnZ2dnUVZ_gednZ2d@speakeasy.net>, Mikhail Teterin <usenet+mill@aldan.algebra.com> wrote: >$txml selectNodes {//*[@xc:value!="FOO" and @xc:value!="BAR"}

You seem to have a missing close-bracket, but I assume that's a typo.

Otherwise the XPath looks reasonable - I don't know anything about tDOM..

Bear in mind that @foo != "bar" means "there exists a foo attribute
not equal to 'bar'".  A node with no foo attribute doesn't pass.

>I tried it with and without the xc:-prefix... What am I doing wrong?

Presumably you are doing whatever is necessary to bind that prefix.

-- Richard
--
:wq

 0
richard91 (3692)
5/2/2008 8:41:48 PM
Mikhail Teterin wrote:
>  $xml selectNodes {//mp:date} > > does not find any, but > >$xml selectNodes {//*[name()="mp:date"]}
>
> works. What's the reason for the difference?

XPath is namespace-aware. To select a namespaced node, you must use a
prefix in your path (which you did) and tell your XPath evaluator what
the prefix bound to (which you didn't). Look at the user's manual for

(comp.lang.xml doesn't exist on my server, so I can't crosspost there.)

 0
5/2/2008 9:02:03 PM
Joseph J. Kesselman wrote:
> XPath is namespace-aware. To select a namespaced node, you must use a
> prefix in your path (which you did) and tell your XPath evaluator what
> the prefix bound to (which you didn't). Look at the user's manual for

Thanks. After I explicitly set:

$xml selectNodesNamespaces {mp MarketParameters xc XmlCache} I got some progress... But the namespaces are defined in the document itself -- for example: <xc:XmlCache xmlns:xc="XmlCache" xc:action="Update"> why do I still need to specify them? It certainly works with xml_grep... Is there a bug in the package (tDOM), or is the above element not sufficient to define a namespace? Thanks! Yours, -mi   0 mill (61) 5/2/2008 9:56:25 PM Mikhail Teterin wrote: > But the namespaces are defined in the document itself > -- for example: > <xc:XmlCache xmlns:xc="XmlCache" xc:action="Update"> > why do I still need to specify them? It certainly works with xml_grep... Is > there a bug in the package (tDOM), or is the above element not sufficient > to define a namespace? Basically, namespaces and XPath don't sit too well together (when the XPath expression is located in an XML document) because the document namespace context at the point in the document where the XPath is located is shrouded from the expression (because it is formally an xsd:string, which is not namespace-aware according to the namespaces spec). This means that if you're embedding an XPath expression in an XML document, you also need to embed a way to tell it what the namespace context to evaluate in is. (This is stupid, but the way it is and isn't a Tcl problem at all.) If the XPath expression is not contained in some XML context, then it is even more obvious that the namespace context needs to be given. Donal.   0 5/2/2008 10:56:14 PM Mikhail Teterin wrote: > I got some progress... But the namespaces are defined in the document itself > -- for example: > <xc:XmlCache xmlns:xc="XmlCache" xc:action="Update"> > why do I still need to specify them? Because they could be set differently at different places in the document, and/or whatever generated your XPath might have different prefixes bound to those namespaces or vice versa. You need to provide a context so the system knows what you meant. Some processors will let you specify a context node and will pick up the namespaces defined there. Again, check your docs. > It certainly works with xml_grep I don't know xml_grep, so I can't advise. It may be assuming the root node as the context if not told otherwise. Or it may be flat-out broken and not processing namespaces correctly. Say what you mean. The system can't read your mind, and shouldn't try.   0 5/2/2008 11:04:50 PM > Basically, namespaces and XPath don't sit too well together It works fine when you understand how to use it properly. The only real problem is that XPath relied on prefixes retrieved from some unspecified environment (depending on the context/tool in which the XPath is being executed). That's a bit less verbose than using an "expanded qualified name" like {http://my_namespace}foo, or requiring that the namespace bindings be specified via some syntax in the XPath string. But it does mean that an XPath is partly defined by that context. (Then again, XPaths which use variables also need a context, as do those which use some of the functions, so this is just the most obvious -- and most unnecessary -- instance thereof.) It is possible to write a portable namespace-aware XPath that doesn't rely on prefixes (via some ugly predicate hacks)... but it really should be easier to do so. Oh well. 20:20 hindsight; maybe XPath 3.0 will finally reconsider that point. By the way: The namespaces shown in the original example are not considered acceptable by today's standards. Namespace names should be fully-qualified ("absolute") URI References. Yes, the original namespace spec was fuzzy about that, and many tools won't enforce this... but after much painful debate, the W3C agreed that the concept of a "relative namespace" really didn't make any sense no matter how you sliced it. Tim Berners-Lee reserves the right to reintroduce that idea if and when the Semantic Web effort comes up with a way to make those meaningful... but until then, you really should make sure all your namespace names follow the official absolute-URI-reference syntax.   0 5/2/2008 11:14:02 PM Joseph J. Kesselman wrote: > The system can't read your mind, and shouldn't try. I don't want it to read my mind, I want it to read the document. The namespaces are set there with an xmlns-attribute of containing elements. In fact, when I for the node's name [$node nodeName], I get the
fully-qualified foo.bar.woof.meow.

It KNOWS the namespace-mapping, but it wants me to repeat it (f means foo, b
means bar, w means woof, etc.). That's gratuitous...

-mi


 0
meow (29)
5/3/2008 4:04:19 PM
In article <14831708.fxxoTTJthF@aldan.algebra.com>,
Mikhail Teterin  <usenet+meow@aldan.algebra.com> wrote:

>I don't want it to read my mind, I want it to read the document. The
>namespaces are set there with an xmlns-attribute of containing elements. In
>fact, when I for the node's name [$node nodeName], I get the >fully-qualified foo.bar.woof.meow. > >It KNOWS the namespace-mapping, but it wants me to repeat it (f means foo, b >means bar, w means woof, etc.). That's gratuitous... Suppose you try to use the same XPath expressions with a document that uses different prefixes. How's that going to work? Your XPath expressions will all be wrong. The choice of prefixes is supposed to be arbitrary. You can't rely on f meaning foo. Even within a single document, you can use the same prefix for different namespaces and different prefixes for the same namespace. -- Richard -- :wq   0 richard91 (3692) 5/3/2008 5:35:38 PM Joseph J. Kesselman wrote: > It is possible to write a portable namespace-aware XPath that doesn't > rely on prefixes (via some ugly predicate hacks)... but it really should > be easier to do so. Oh well. 20:20 hindsight; maybe XPath 3.0 will > finally reconsider that point. It'd be OK if there was a type "like xs:string, but understands the current namespace context" but there isn't. (Of course, once you extract the XPath from its context document you then need to remember to explicitly get the NS context from somewhere, which is almost certainly the root of the problem in the message that started this thread.) Donal.   0 5/3/2008 9:19:35 PM Mikhail Teterin wrote: >Joseph J. Kesselman wrote: >> XPath is namespace-aware. To select a namespaced node, you must use a >> prefix in your path (which you did) and tell your XPath evaluator what >> the prefix bound to (which you didn't). Look at the user's manual for >> your tool. > >Thanks. After I explicitly set: > >$xml selectNodesNamespaces {mp MarketParameters xc XmlCache}

That's the right way to bind prefixes to a namespace. One way. You can
always use the -namespaces option to the selectNodes method, but
setting things up with one selectNodesNamespaces call for the rest of
the lifetime of the document seems to be more convenient to me.

>I got some progress... But the namespaces are defined in the document itself
>-- for example:
>
> <xc:XmlCache xmlns:xc="XmlCache" xc:action="Update">
>
>why do I still need to specify them? It certainly works with xml_grep... Is
>there a bug in the package (tDOM), or is the above element not sufficient
>to define a namespace?

No, it's not a bug. As long as no selectNodesNamespaces setting nor
the -namespaces option is given, tDOM even respects the XML namespace
declarations of the document. The context node of your XPath
expression is the node, from which you call your XPath expression. If
the (all) prefixes, you're using in your XPath expression are in scope
of that node, you've to do nothing; namespace resolving will work as
you expect. Since you had trouble with this, I'd bet, not all used
XML namespace declarations are in scope of your context node.

But, as others already have pointed out, it is _dangerous_ to bank on
the prefixes in the document. Prefixes don't matter, it's the
namespaces, that matters.

From the XML viewpoint,

<a:doc xmlns:a="http://foo.bar.com">
<a:elem>data</a:elem>
</a:doc>

and

<b:doc xmlns:b="http://foo.bar.com">
<b:elem>data</a:elem>
</b:doc>

are the in some sense the 'same' documents.

You can't just say [$someNode selectNodes a:elem] in your code and expect that to work reliable. If the document provider uses another prefix (bound to the same namespace), your code will fail. The clear way out is, to say the XPath engine, which namespace you mean with which prefix. With e.g. selectNodesNamespaces. rolf   0 pointsman (41) 5/6/2008 10:37:46 AM  Reply: Similar Artilces: text-text Wondering how what I input to my UTF-8 terminal gets passed along through my patched [1] trn ... Cyrillic: А Б В Г Д Е Ж З И Й К Л М Н О П а б в г д е ж з и й к л м н о п IPA: ᴀ ᴁ ᴂ ᴃ ᴄ ᴅ ᴆ ᴇ ᴈ ᴉ ᴊ ᴋ ᴌ ᴍ ᴎ ᴏ ɀ Ɂ ɂ Ƀ Ʉ Ʌ Ɇ ɇ Ɉ ɉ Ɋ ɋ Ɍ ɍ Ɏ ɏ [1] https://groups.google.com/d/msg/comp.sys.raspberry-pi/7Z37Hdrm0DM/6aqD-reXFzAJ ... text + text What is "text + text" supposed to do right now? It doesn't seem very useful to me. What about making "text + text" as an equivalent for "text || text"? Most strongly-typed programming languages do this. And MS SQL Server too, I think (CMIIW). -- dave ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org Am Freitag, 8. Oktober 2004 12:57 schrieb David Garamond: > What is "text + text" supposed to do right now? Nothing. > What about making "text + text" as an equivalent for "text > || text"? Most strongly-typed programming languages do this. And MS SQL > Server too, I think (CMIIW). What would this gain except for bloat? It's not like SQL is utterly compatible with any programming language; users will still have to learn all the operators anyway. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match Peter Eisentraut wrote: >>What is "text + text" supposed to do right now? > > Nothing. Then are these bugs? (7.4.5 and 8.0.0beta1 give same results). Frankly, the current behaviour is quite strange to me. ------------------ =... Adding and updating new tDOM XML text nodes Hi guys, Some code: package require tdom # Read in data in the xml variable. set dom [dom parse -keepEmpties \ "<BASE>\n<al>\n<Cats>9 lives</Cats>\n<Canaries/>\n</al>\n</BASE>"] set doc [$dom documentElement] # Add a missing node. set node [$doc selectNodes /BASE/al]$node appendXML "<Dogs></Dogs>" # Update an existing node. set node [$doc selectNodes /BASE/al/Cats/text()]$node nodeValue "Great swingers" # Output doc to show Dogs got added and Cats changed. puts [$doc asXML] # Try to update the node with some data. set node [$doc selectNodes /BASE/al/Dogs/text()] $node nodeValue "Go Woof" Output: <BASE> <al> <Cats>Great swingers</Cats> <Canaries/> <Dogs/> </al> </BASE> invalid command name "" while executing "$node nodeValue "Go Woof"" (file "t" line 15) Platform: ActiveTCL 8.4.13.0.261555. Strangeness: I can add the new node to the XML (and it's even reformatted) for it to be called in when doing the $doc asXML, but, I can't update a newly added node. Anyone have any suggestions? In article <slrneh8g2p.irn.flavp+hfrarg@sparrow.autons.net.au>, Synic <flavp+hfrarg@nhgbaf.arg.nh> wrote: >Some code: > > package require tdom > # Read in data in the xml variable.... xsl variable$node/text() but $node can non-node-set help! I have a variable$value as a parameter in the following template: <xsl:template name="myTemplate"> <xsl:param name="value"/> <xsl:if test="$value"> <xsl:value-of select="$value"/> </xsl:if> </xsl:template> Now i call myTemplate sometimes whit the a parameter $value that is sometimes a text node, and sometimes it is not even a node. Example: <inputDoc> <a>hello</a> <a/> </inputDoc> xsl: <xsl:for-each select="/inputDoc/a"> <xsl:call-template name="myTemplate"> <xsl:with-param name="value" select="./text()"/> </xsl:call-template> </xsl:for-each> So i call myTemplate with parameter$value=a/text() But for the second <a> element in <inputDoc> there is not text() node. This gives me the following error: Cause: javax.xml.transform.TransformerException: The value is not a node-set With line number of the error pointing to the xsl:if in myTemplate. No i tried the function nilled(), but that is XPath 2.0, i only use XPath 1.0 and XSL 1.0 i know a possible solution is this: <xsl:for-each select="/inputDoc/a"> <xsl:choose> <xsl:when test=".[not(node())]"> <xsl:call-template name="myTemplate"> <xsl:with-param name="value" select="false()"/> </xsl:call-template> <...

How to find non-existing nodes or nodes with no text
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this: i.e. 1 <discography> <CD> <title></title> <year>1978</year> </CD> </discography> i.e. 2: <discography> <CD> <year>1978</year> </CD> </discography> In i.e. 1, the tag <title> is empty. How do i test for empty tags in PHP? In i.e. 2, the tag <title> doesn't even exist. How do i ...

Non-XML tagged value text to XML
I would like to use XSLT to translate some tagged value text to XML elements like this: Input Doc: <data>x=1.234 y=ABC z="Hello World"</data> Output Doc: <x>1.234</value> <y>ABC</y> <z>&quot;Hello World&quot;</z> Is XSLT up to the task? What would it look like? Most of the XSLT string processing code I've seen looks very verbose - can't be too efficient. mikea_59 wrote: > I would like to use XSLT to translate some tagged value text to XML > elements like this: > > Input Doc: > > <data>x=1.234 y=ABC z="Hello World"</data> > > Output Doc: > > <x>1.234</value> > <y>ABC</y> > <z>&quot;Hello World&quot;</z> > > Is XSLT up to the task? What would it look like? Most of the XSLT > string processing code I've seen looks very verbose - can't be too > efficient. Using XSLT 2.0 you can do that with regular expression matching as follows: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <results> <xsl:apply-templates /> </results> </xsl:template> <xsl:template match="data"...

XML DOM: XML/XHTML inside a text node
In my program, I get input from the user and insert it into an XHTML document. Sometimes, this input will contain XHTML, but since I'm inserting it as a text node, xml.dom.minidom escapes the angle brackets ('<' becomes '&lt;', '>' becomes '&gt;'). I want to be able to override this behavior cleanly. I know I could pipe the input through a SAX parser and create nodes to insert into the tree, but that seems kind of messy. Is there a better way? Thanks. On Thu, 2 Nov 2005 noahlt@gmail.com wrote: > In my program, I get input from the us...

XSLT Select nodes without text-node children whose names starts with specifix text
Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="10" detail="true"> <onefield>onefieldstext</onefield> <fgman9>fgmanfieldstext</fgman9> <twofield>twofieldstext</twofield> </Line> <Line no="11" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="12" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> <Line no="13" detail="true"> <onefield>onefieldstext</onefield> <fgman5>fgmanfieldstext</fgman5> <twofield>twofieldstext</twofield> </Line> <Line no="14" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line> </Page> </Body> I would select the <Line/> nodes without text-node children whose names is starting with "fgman" - in this example it is all <Line/> _except_ <fgman9/> and <fgman5/> in <Line/> with @no of 10 and 13. I know that this works: &...

file command: "XML document text" vs "XML document text"
I've just used the file command on four files of RDF-XML with the following output: augtfidf.rdf: XML document text kyoto.rdf: XML document text stuff.rdf: XML document text tfidf.rdf: XML document text What does it mean that one of them has an extra space between "XML" and "document"? -- The kid's a hot prospect. He's got a good head for merchandising, an agent who can take you downtown and one of the best urine samples I've seen in a long time. [Dead Kennedys t-shirt] On 16.10.2012 16:06, Adam Funk wrote: > I've just used the file command on four files of RDF-XML with the > following output: > > augtfidf.rdf: XML document text > kyoto.rdf: XML document text > stuff.rdf: XML document text > tfidf.rdf: XML document text > > What does it mean that one of them has an extra space between "XML" > and "document"? Hard to tell without further information. What does file *.rdf | od -c show you? Janis Janis Papanagnou wrote: > On 16.10.2012 16:06, Adam Funk wrote: >> I've just used the file command on four files of RDF-XML with the >> following output: >> >> augtfidf.rdf: XML document text >> kyoto.rdf: XML document text >> stuff.rdf: XML document text >> tfidf.rdf: XML document text >> >> What does it mean that one ...

Distinguish text URLs from non-text URLs?
Hello, I have a question when trying to use Java to program a crawler like program. As I only need the text (html) files, I am wondering whether anyone know a good way to distinguish text URLs (files such as html, htm, etc) from non-text URLs? What I want is: given a String type url, how can I decide whether this URL points a text file (.htm, etc) or not? We know text pages usually have URLs ending with .htm, .html, etc. But with many dynamic pages, such as in http://www.amazon.com/exec/obidos/ASIN/B00006HXJ6/ref=nosim/fatwalletcom/002-5149236-2409652 this URL points to a html page, but its ...

Text from required text box to read-only text box
Hello, I am fairly new to JavaScript and its use in Acrobat Professional. My situation is this: I have a form with a text box field which is required for the user to enter his/her name. I would like the required text box to display the name in all caps. I also need the user's name to appear in a read-only text box later in the form, which I would like to have the first letter of the user's first, middle initial, and last names to be capitalized. I would also like to have all required fields on the form highlighted in yellow, but the highlighting not printed. Lastly, I would like the...

Surrounding text with text
I was wondering if it was possible to surround a text body with text like so: +--------------+ |ABCDEFGHIJKLM | |H N| |A Main Body O| |L Text goes P| |B here Q| |-=+_ZYXWVUTSR | | | | | | | | | +--------------+ This seems far-fetched, but just curious. I suppose that I could just move stuff around by hand in the GIMP later on, but there's probably a {better,more {extensible,clean}} way of doing it from (La)TeX. -FreeSmith ptjm@interlog.com (Patrick TJ McPhee) wrote in message news:<bffbhe$per$1@news.eusc.inter.net>... > Peter Flynn had an example like that, which he either posted here or > posted a link here. It was something to do with a certificate -- try > searching for his name and that word in google. > > It wouldn't be hard to do with metapost. I have a macro called `pathalong' > which puts text along an arbitrary path. Well, it's been a while, but I finally finished it. It's a little job I was doing for an upcoming wedding. At any rate, I used pstricks to make the text go along a path, along with a couple of hacks for sizing (from graphicx) and kerning along the line (from soul). Here's the code (don't laugh): CAUTION:THIS CODE MAY MAKE YOU WRETCH ---SNIP--- \documentclass{article} \usepackage{graphicx} \usepackage{pstricks,pst-text,nopageno} \usepackage[width=8.5in]{geometry} \usepackage{soul} \begin{document} \thispagestyle{empty} \set...

text 2 text
I'm rather new to ustation and am having trouble finding replacements for all of my Acad lisp routines. One that I'd like to find changes a selected text string to read like the second selected text string. I realize this can all be done in the text editor but it's not all that quick. Does anyone know of a macro or mdl which can handle this task? Thanks in advance.---Calvin I don't know of any application that will do what you describe, but have you looked at Edit > Find/Replace text? You may also find Bentley's discussion groups of assistance. Over there you can meet other users of Bentley products, exchange ideas, and discuss a wide range of technical subjects. These groups are an excellent technical resource for all users of Bentley products and services. Hope to see you there! For more information take a peek at this page: http://selectservices.bentley.com/discussion/index.htm -- Best Regards, Inga Morozoff [Bentley] www.askinga.com "jgonzales24" <jgonzales24@cox.net> wrote in message news:xcLMb.13975$zs4.2376@fed1read01... > I'm rather new to ustation and am having trouble finding replacements for > all of my Acad lisp routines. One that I'd like to find changes a selected > text string to read like the second selected text string. I realize this > can all be done in the text editor but it's not all that quick. Does anyone > know of a macro or mdl whi... Quickly adding text to a mysql text field that is NOT empty Hi all Is there a way to insert text into a mysql text field that already has text into it; without having first to extract the existing data and append the new text to that string variable and then insert the new string. Basically i'm looking for a way to do it with a single query not 2 (one being a select to gather existing data). Please help! I could have sworn I already replied to this but it appears that it did not go through, but anyway; you want to modify the contents of an existing field without having to fetch it using a query, yes? This is possible through the use of MySQL&#... Pages I have a titel-textfield over a pic (headline) , text is black, background for text transparent. A second textfield should overlapp the first textline..... When i arrange the second field with the same settings like the first, the first text disappear... How can i do, that the second text overpapps the first, all over the pic. Any help appreciated! Thanks for replies! I am german and hope that the engish speaking people understand my problem! Soory! Gerd In article <611db9e2-b085-4fe5-907a-ca714b0c32dd@m74g2000hsh.googlegroups.com>, hurlebaus <gerd.schenk@freenet.de> wrote:... Removing non-text/whitespace chars from a text file: How ? When I highlight and copy test from a web browser and past it into a text file I frequently get extended ascii non-text bytes that I'd like to strip out. I like to remove anything above octal 126. What's the right tool for this ? Thanks -- a d y k e s @ p a n i x . c o m Don't blame me. I voted for Gore. Al Dykes wrote: > When I highlight and copy test from a web browser and past it into a > text file I frequently get extended ascii non-text bytes that I'd like > to strip out. I like to remove anything above octal 126. What's the > right tool for thi... Getting kind of abstract text snippets from text nodes Hi everybody, I am about implementing a little search engine that searches a phrase over xml text nodes. I got that all working fine but what I want as the results is not the complete text of the textnode, I would like to make an abstract like result list (such output that you get with google searches. For eg .... I am the <b>substring</b> from a complete text node ... where "substring" is the search term. The problem is simple (I think): I want to extract all the text parts of the complete text node, where search searchterm is highlighted, surrounded by the text like 30 characters. I found an intersting post "cut down text" which is almost that what I am looking for, but there the text is just trimmed by x characters. Is anybody here, that has an "elegant" way to solve that or some hints that get me to the solution? I am not able to use regex (would be nice though) My parser is Sablotron so I am restricted to the functions that I get. (1.0). Any help is greatly appreciated. regards, Andreas W Wylach Think about dividing the text into three parts: before your target, the target itself, and after the target. Process each appropriately. If you want to report multiple instances within the same block of text, look at the standard examples of recursive text processing. -- () ASCII Ribbon Campaign | Joe Kesselman /\ Stamp out HTML e-mail! | System architexture and kinetic poetry "Andreas W. Wylach" <aw@ioc... extracting text from an XML node Hi, suppose i get the simple xml sample: <foo> 1 <bar>2</bar> 3 </foo> Now suppose i want to extract all the text of only the 'foo' node, ie expected result is '1 3'. I tried both <xsl:template match="foo"> <xsl:value-of select="text()" /> </xsl:template> and <xsl:template match="foo"> <xsl:value-of select="." /> </xsl:template> but the former lead to '1' and the latter to '1 2 3' (using xsltproc & firefox). What did i missed ? thanks, -Nicolas nicolas.edel@gmail.com wrote: > Now suppose i want to extract all the text of only the 'foo' node That isn't a built-in concept; you have to recast it as "all the text nodes which are immediate children of the 'foo' node". (The built-in text value of an element, as you discovered, is the value of all text contained in it, directly or indirectly). Note too that the whitespace (line breaks and indentation) will be part of the the text nodes unless you explicitly strip that away. <xsl:value-of select="text()" /> didn't work because value-of returns the contents of only the first matching node. This is one case where xsl:for-each is appropriate, to explicitly iterate through the text children. -- Joe Kesselman / Beware the fury of a patient man. -- John Dryden On Nov 30, 12:34 am, Joseph Kesselman <kesh... text node has text but won't render This renders in Firefox perfectly well but the text in the red box remains invisible. The program is a subset of a larger and doesn't do much. but even after cutting out all the unneccessary stuf, I still can't get it to work!! Cheers, Greg =================== <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" > <xhtml:head> <xhtml:title> Intermingled XHTML and SVG </xhtml:title> <xhtml:script type="text/javascript" language="JavaScript"><![CDATA[ function gogo(evt){ var targetObj = evt.target; //The object that received the event var targetDoc = targetObj.ownerDocument; //Owner document var wg = document.getElementById("SVGroot"); var lg = document.getElementById("labelz"); //label labelBox= targetDoc.createElementNS("http://www.w3.org/2000/svg", "svg:rect"); labelBox.setAttributeNS(null, "id", "label1"); labelBox.setAttributeNS(null, "fill", "red"); labelBox.setAttributeNS(null, "fill-opacity", 1); labelBox.setAttributeNS(null, "x", 700); labelBox.setAttributeNS(null, "y", 400); labelBox.setAttributeNS(null, "width", 200); labelBox.setAttributeNS(null, "height", 20); labelBox.setAttributeNS(null, "visibility", "visible"); lg.appendC... Read a non text file How can i convert a weird looking file to text file. I know the main info is stored in the file which looks like below. " ����<t���Jч�ĉTV��y�rr�  �Ph"e~Wm>�E�0Y'p�=C�&�rؙ�<t�Fx�Zo$�+T��=���H Or�r6�S��m&7<�p�q��� u����w}�jlꥎ+_�����Z�?��v��ȉ�XC R�}�_�׍�:�\$)�o}��NʨW\&���I@b�#T�B��8���J��CL�ypr\�]R���p\��S�XRҏ�f&?/��� 2�t�_��x���bG���Z�D�v�s [�"��N�# Ѡ�@)�����h'&%�(�)��c�ͼA ���zUZjLRyu�P̤� ��� �W��e�@1'�(��u-nG��p��2_�� T&�6+� _� d�(1Z�E@���h�F�z �~x�fG���s�b�/-+�@��0�%��6�wu�=��z���Y�0...

Is there a way to display alternate text in a text box if field is empty
The Results Form I am working on has a field for price. Some of the records do not have price at this time. Is there a way to program the text box to read, "Contact Whoever for details" if the field price is left blank. Or will I just have to put that message in the price field in the table for every record that I don't want to put the price in right now. You "could" just set the default value for the text box to that value, and if the users don't know the price, then that value will be saved with the record. If they do know it, they can simply erase the default...

editor for editing xml text nodes
We have xml documents which contain text imbedded as text content in some xml structures. These documents need to be translated by human translators from English into, for example, Chinese. We would like the translator to use an editor which shows him only the text content of the xml document, or gives him only editing access to the text content. The translator should be unable to touch or modify the xml tags, so that it is guaranteed that the xml-tags are unchanged when the translator returns the translated document. The translator simply replaces all English text accessible to him into Chinese text. Does anyone know an xml editing tool which has this feature, of allowing only modification to the text node content? Alois Zreindl wrote: > We have xml documents which contain text imbedded as text content in > some xml structures. > > These documents need to be translated by human translators from English > into, for example, Chinese. > > We would like the translator to use an editor which shows him only the > text content of the xml document, or gives him only editing access to > the text content. I am working on exactly this right now. It leaves the elements in element content inviolable, but allows element markup in mixed content (the only thing a translator should be touching). Please contact me by email to discuss this further. > The translator should be unable to touch or modify the xml tags, so that > it is guara...

Empty text node throws NullPointerException
I have a line of code like this: String textnode = node.getFirstChild().getNodeValue(); It works fine for: <MyElement>MyValue</MyElement> But throws NullPointerException for: <MyElement></MyElement> Yet the latter case is OK in my business logic - I don't want to throw, I want to continue parsing. Is there a way to test before the exception, or simply return a null value to my textnode String above? iksrazal "iksrazal" <iksrazal@terra.com.br> > I have a line of code like this: > > String textnode = node.getFirstChild().getNodeValu...

Why treat text nodes as nodes?
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object when they have virtually nothing in common. The reason these APIs do it is to make it possible for both text and elements to be children of elements. But there is another way. The XPath/XQuery data model does not allow two consecutive text nodes. As far as I can tell, most XML processing software automatically merges consecutive text nodes. This means that the number of text segments directly under an element is bound by the number of sub-elements plus 1 (PIs and comments may be treated as "pseudo-elements" for this purpose). As a result, it is always possible to associate each text segment with the element immediately preceding it within the parent and associate the first text element with the parent itself. No more text nodes. The only API I know that uses this trick is the ElementTree API for Python by Fredrik Lundh (http://effbot.org/zone/element-index.htm). Each Element object has a text and tail property for the text immediately inside the element and text following it within its parent element. Elements always have a tag, attributes and and zero or more children - which are always other elements. No mixed types. The text and tail attributes are always strings. This model should be very convenient for statically-typed languages like Java or C++. I find it ironic that this idea is probably used only in Pyt...

Web resources about - XPath for non-empty #text nodes (tDOM) - comp.text.xml

Resources last updated: 3/13/2016 9:40:36 PM