I need to find out the index (position) of XML element with certain attribute and namespace. In my XML there are more elements with the same name so only possible way to identify the right one is by its attribute.
This is sample of my XML document:
<mets:mets LABEL="Moderní pedagogika, 2002" TYPE="Monograph"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:mets="http://www.loc.gov/METS/"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:ns3="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:ns5="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd">
<mets:metsHdr CREATEDATE="2012-12-05T07:42:22" LASTMODDATE="2012-12-05T07:42:22">
<mets:agent ROLE="CREATOR" TYPE="ORGANIZATION">
<mets:name>ABA001</mets:name>
</mets:agent>
<mets:agent ROLE="ARCHIVIST" TYPE="ORGANIZATION">
<mets:name>ABA001</mets:name>
</mets:agent>
</mets:metsHdr>
<mets:dmdSec ID="MODSMD_VOLUME_0001">
.....
</mets:dmdSec>
<mets:dmdSec ID="DCMD_VOLUME_0001">
.....
</mets:dmdSec>
</mets:mets>
Desired Index in this case is the index of this tag <mets:dmdSec ID="MODSMD_VOLUME_0001">
I have tried some solution regarding list(root).index(dmdSec) but without success since I am not able or do not know how to insert there details about attribute and namespace
Could someone help me with this
I'm assuming that you are using the lxml.etree library for xml parsing - if not you may have to modify things a bit - but the principle is the same:
Simply use:
Edit:
from lxml import etree
root = etree.parse(r'path\to\your\file.xml')
int(root.xpath('count(//*[#ID="MODSMD_VOLUME_0001"]/preceding-sibling::*)+1'))
Output:
2.
Note that the position is 2 and not 1 - xpath counts from 1 (unlike python, which counts from 0). Your target is the second <mets:dmdSec> node within the root.
I have gathered obligatory data from the scopus website. my outputs have been saved in a list named "document". when I use type method for each element of this list, the python returns me this class:
"<class'selenium.webdriver.firefox.webelement.FirefoxWebElement'>"
In continius in order to solve this issue, I have used text method such this:
document=driver.find_elements_by_tag_name('td')
for i in document:
print i.text
So, I could see the result in text format. But, when I call each element of the list independently, white space is printed in this code:
x=[]
for i in document:
x.append(i.text)
print (x[2]) will return white space.
What should I do?
As you have used the following line of code :
document=driver.find_elements_by_tag_name('td')
and see the output on Console as :
"<class'selenium.webdriver.firefox.webelement.FirefoxWebElement'>"
This is the expected behavior as Selenium prints the reference of the Nodes matching your search criteria.
As per your Code Attempt to print the text leaving out the white spaces you can use the following code block :
x=[]
document = driver.find_elements_by_tag_name('td')
for i in document :
if (i.get_attribute("innerHTML") != "null") :
x.append(i.get_attribute("innerHTML"))
print(x[2])
My code was correct. But, the selected elements for displaying were space. By select another element, the result was shown.
I am importing text values into a transformation using a Fixed Width input step. Everything is coming in as a string. I want to convert some of the string values to integers with a decimal point at a specified spot. Here are some examples of the before (left hand side) and expected results (right hand side):
00289 --> 0028.9
01109 --> 0110.9
003201 --> 0032.01
I've tried numerous combinations of the Format mask in a Select Values step (meta data tab) but I can't get the values I'm looking for.
Can you anyone tell me what combination I can try for* Type/Length/Precision/Format/Encoding/Decimal/Group* attributes for these fields to get the desired output?
Have you tried another step the reach your goal? You can try to use e.g. User Defined Java Expression setting it in this way:
Java expression: new java.math.BigDecimal(text.substring(0,4) + "." + text.substring(4,text.length()))
Value type: BigNumber
But this will convert your input to:
00289 --> 28.9
01109 --> 110.9
003201 --> 32.01
Because its output is BigNumber format. BigNumber or Number format can be used for decimal numbers. You cannot use Integer for decimals because it has no decimal part.
If you want a String output leave out the new java.math.BigDecimal() part from the expression above and set Value type to String. It will produce these results:
00289 --> 0028.9
01109 --> 0110.9
003201 --> 0032.01
This is the one suggestion. Of course there are another ways of how to reach your goal.
I am tring to plot a map with d3.js using GeoJSON, but the paths generated look like this:
<path d="MNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNLNaN,NaNZ">
the code and data are in this Gist:
https://gist.github.com/4157853
I can load the data just fine on QGIS.
Does any one know what is causing this?
The way you have specified the offset in the Mercator projection doesn't seem right. The projection.translate method expects a two element array:
https://github.com/mbostock/d3/wiki/Geo-Projections#wiki-mercator_translate
So instead of:
proj.translate(-43.8,-23.2).scale(10);
you would need to say:
proj.translate([-43.8,-23.2]).scale(10);
-- edit --
See source of projection.translate: https://github.com/mbostock/d3/blob/3.0/src/geo/projection.js#L139
projection.translate = function(_) {
if (!arguments.length) return [x, y];
x = +_[0];
y = +_[1];
return reset();
};
If the argument _ is not an array then +_[0] will return a NaN and therefore the x and y will become NaNs. (This is because trying to get one element from a number (e.g. 213[0]) returns undefined and casting undefined to a number (e.g. +undefined) yields NaN.)
If the code you posted in the gist is everything you're trying to run, then the data you show in data.json is not being loaded anywhere. Anyway, your draw function is acting on the data defined by the variable map (line 16), which refers to a simulation variable which isn't set anywhere. And even if it did, line 34 then refers to a features property of the object passed in as json, which map does not have.
In summary, you need to pass the JSON you posted in the gist to your draw function. Then it might well work. If you don't pass in valid data to the d3 SVG helpers, you'll get a bunch of NaN out.
It seems that Excel's handling of the metadata you can associate with cells is broken, but I'd be interested to hear if anyone else has tried (successfuly or otherwise) to use this feature.
Since there doesn't seem to be a way to report bugs against Excel, I've posted a full description of the problem with code to reproduce it here:
http://social.technet.microsoft.com/Forums/en-US/excel/thread/c7f9747a-1d03-4415-97d4-d9aa58b4d240 but I'll repeat the salient details.
In short it seems that Excel is removing, and incorrectly re-indexing the metadata I programatically associate with cells.
First, a summary of the relevant parts of the specification:
From OOXML 18.9: There are two types of metadata: "cell metadata" and "value metadata".
Cell metadata follows the cell as it moves. Value metadata follows the value through formulae etc.
From OOXML 18.3.1.4: The c (cell) element has cm and vm attributes which are both documented as "The zero-based index of the [cell|value] metadata...in the Metadata Part"
From OOXML 18.9.17: The valueMetadata is "a collection of block element that each define the value metadata for a particular cell". "Cells in the workbook index into this collection".
The valueMetadata contains bk elements which in turn contain rc (metadata record) elements
From OOXML 18.9.15: rc elements have t (type index) and v (value index) attributes. t is a 1-based index into metadataTypes and v is a 0-based index into the futureMetadata element which matches the name of the metadata type.
Here's an example of what that might look like:
...
<c vm="0"> <!-- vm points to the first bk inside valueMetadata below -->
...
<x:valueMetadata>
<x:bk>
<x:rc t="1" v="0" /> <!-- t points to the first metadataType below. v points to the first bk in the futureMetadata below (whose name matches the metadataType to which t points) -->
</x:bk>
</x:valueMetadata>
...
<x:metadataTypes>
<x:metadataType name="MyMetaType" ... /> <!-- name dictates which futureMetadata valueMetadata's v attribute indexes into -->
</x:metadataTypes>
...
<x:futureMetadata name="MyMetaType" ...>
<x:bk>
<x:extLst>
<x:ext xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main" uri="http://example.com/extension" p5:value="test value" xmlns:p5="http://example.com/extension" />
</x:extLst>
</x:bk>
</x:futureMetadata>
...
The Problem
From what I can tell, for values of n > 2, if you associate n cells with metadata, Excel will drop the last piece of metadata, and the one at index 1, and it will do so silently. The indices are then 0..n-3, and the association for all but the first (0 index) will be wrong. This renders the future metadata totally useless.
For n == 1, Excel just removes the last piece of metadata (index 1). If we try 1-based indexes for the vm attribute on the c element, we get different behaviour. This may not be relevant as it is contrary to the specification, but the slightly better behaviour might indicate an off-by-one error:
n Deleted Indices (0-based) Deleted Indices (0-based)
when using 0-based indices when using 1-based indices
1 0 None
2 1 1
3 1,2 1
4 1,3 1
5 1,4 1
6 1,5 1
A suitable workaround from here.
Bit late to the party but only recently started using OpenXML. Easiest fix is to avoid Metadata and just use extension lists. They can be customised and applied at the cell level.
So instead of fiddling around with the metadata part, you can just write this to avoid the problem, you mentioned:
<c>
<extLst>
<ext uri="http://example.com/extension" p5:value="test value" xmlns:p5="http://example.com/extension">
<p5:anotherValue>127</p:anotherValue>
</ext>
</extLst>
</c>