How do get element out of xml file - vb.net

I get an XML file From a web service. Now I want to get one of those elements out of the file.
I think I should go use XPath - any good starter reference?

I've just been recovering my XPath skills- this Xslt and XPath Quick Reference sheet is quite a useful reference - it doesn't go into depth but it does list what is available and what you might want to search for more information on.
The w3schools tutorial linked previously isn't that great - it takes a long time to not cover a lot of ground - but it is still worth reading.

Not VB specific, but try this: http://www.w3schools.com/xsl/xpath_intro.asp

One way would be to only extract the needed informations with an xslt file into a new xml and use this new xml as data basis for further processing

If I need to do some XPath, I just tweak one of these examples.
child::node() selects all the children of the context node, whatever their node type
attribute::name selects the name attribute of the context node
attribute::* selects all the attributes of the context node
descendant::para selects the para element descendants of the context node
ancestor::div selects all div ancestors of the context node
ancestor-or-self::div selects the div ancestors of the context node and, if the context node is a div element, the context node as well
descendant-or-self::para selects the para element descendants of the context node and, if the context node is a para element, the context node as well
self::para selects the context node if it is a para element, and otherwise selects nothing
child::chapter/descendant::para selects the para element descendants of the chapter element children of the context node
child::*/child::para selects all para grandchildren of the context node
/ selects the document root (which is always the parent of the document element)
/descendant::para selects all the para elements in the same document as the context node
/descendant::olist/child::item selects all the item elements that have an olist parent and that are in the same document as the context node
child::para[position()=1] selects the first para child of the context node
child::para[position()=last()] selects the last para child of the context node
child::para[position()=last()-1] selects the last but one para child of the context node
child::para[position()>1] selects all the para children of the context node other than the first para child of the context node
following-sibling::chapter[position()=1] selects the next chapter sibling of the context node
preceding-sibling::chapter[position()=1] selects the previous chapter sibling of the context node
/descendant::figure[position()=42] selects the forty-second figure element in the document
/child::doc/child::chapter[position()=5]/child::section[position()=2] selects the second section of the fifth chapter of the doc document element
child::para[attribute::type="warning"] selects all para children of the context node that have a type attribute with value warning
child::para[attribute::type='warning'][position()=5] selects the fifth para child of the context node that has a type attribute with value warning
child::para[position()=5][attribute::type="warning"] selects the fifth para child of the context node if that child has a type attribute with value warning
child::chapter[child::title='Introduction'] selects the chapter children of the context node that have one or more title children with string-value equal to Introduction
child::chapter[child::title] selects the chapter children of the context node that have one or more title children
child::*[self::chapter or self::appendix] selects the chapter and appendix children of the context node
child::*[self::chapter or self::appendix][position()=last()] selects the last chapter or appendix child of the context node
An in depth documentation can be found here. Also these example are taken from there.

Related

Nested predicates in Xpath

I am trying to access the div node via
//div[#data-full='2018-1-15']
Normally I would just search by Xpath and grab this node. However the nature of the site is that there are a number of nodes with this property, and only one is clickable.
Because of this I have to grab the
//div[#class='dw-cal-slide dw-cal-slide-a']
node first and then step down. I know I'm trying to do something like this:
Step down one node:
//div[#class='dw-cal-slide dw-cal-slide-a']/div/
And then search for child nodes that have a child node of their own with the property
//div[#data-full='2018-1-15'].
Having trouble with the syntax. Any help would be great!
Try
//div[contains(#class, 'dw-cal-slide') and contains(#class, 'dw-cal-slide-a')]//div[#data-full='2018-1-15']
But IMHO it's better (shorter expression) to use CSS selector
div.dw-cal-slide.dw-cal-slide-a div[data-full='2018-1-15']
If you want to locate ancestor and descendant div in two code lines, then you can use (Python example)
ancestor = driver.find_element_by_xpath("//div[contains(#class, 'dw-cal-slide') and contains(#class, 'dw-cal-slide-a')]")
and
descendant = ancestor.find_element_by_xpath(".//div[#data-full='2018-1-15']")
As you said, there are multiple node with same property and only one is clickable. you can click on the node by checking isEnable. other thing you can try with following-sibling or preceding-sibling. example can be found on below stackoverflow link:
How to use XPath preceding-sibling correctly

set a node selected by default in dijit.Tree

I'm using dijit.Tree, I need to set a node selected by default (after the data loaded) ? I have tried to search it in dojo documentation, but I didn't find it.
You can select a tree node programmatically by setting the tree's 'path' property. A path is an array of string item id’s, starting with the root node and going down to the leaf node which you want selected.
example:
tree.set('path', ['parent', 'child', 'grandchild'])
In this example grandchild is the node you want selected.
Documentation and examples for this can be found on the Dojo website here

Treeview not finding parent node when adding child node

So I have this Treeview to which I manually add some items.
Parent nodes can be added without problems, but when I want to add a child node to a parent node that I search by key, it fails for some reason.
This is the code:
tvConstantGroups.Nodes.Add("Boekhouding")
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("Exact") 'These 2 lines fail
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("BoB")
The error message that I am getting is that the node "Boekhouding" does not exist (NULL / Nothing)
tvConstantGroups.Nodes.Add("Boekhouding", "Boekhouding")
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("Exact", "Exact")
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("BoB", "Exact")
The first parameter of Nodes.Add is Text Not the Name of Node

Sencha Touch 2: Give a different itemTpl to nested list leaf nodes

In my nested list I have 2 levels. Currently it shows a standard list. When you click an item it takes you to a list of that item's children. Those children are the leaf nodes. So when you tap one of those it takes you to the detail card for that item. I'd like to use a different list item template for the children than the parent items. Is there a way to use Ext.XTemplate to check if an item is a leaf node or not?
Figured it out:
Simply update the x-list-item-leaf class
.x-list-item-leaf{
color:red !important;
}

libxml - looping through all children of a child

I am new to libxml. I would like to write 1 loop to loop through all the children of a child node etc. e.g.
<par>i want to <bold>loop <italic>through </italic> all</bold> children in this node</par>
At the moment my looping code look as follows but I only get the "bold" node and not the "italic" child.
if (xmlStrEqual(node->name, BAD_CAST "p")) {
xmlNodePtr child = node->children;
while (child != NULL) {
child = child->next;
}
}
It is conceivable that the node structure could grow to 4-5 elements, so I need a solution which is more robust that putting while loops within while loops. Any help would be appreciated please.
The xmlTree interface you're using is heirarchical. <par> has 3 children - the text before <bold>, <bold> itself, and the text after. <bold> has children of its own, which includes <italic>. The node->children list only contains the immediate children of a node.
There are a couple ways to get the behavior that you want.
While processing child, you can recursively process child->children to get to <bold>'s child, which includes <italics>
If you're looking SPECIFICALLY for that <itallic> (or for a set of specific nodes), you can use an XPath expression, such as "par//italic" to find any italic node anywhere beneath par.
http://www.xmlsoft.org/examples/index.html#XPath
You could look at libxml2's xmlTextReader interface rather than this xmlTree. It provides the serial "read through" of the document that you're expecting.
http://xmlsoft.org/xmlreader.html
Each method has its own advantages/disadvantages, depending on what all you're trying to do with your application.