XmlDocument SelectNodes: find an element by an attribute value only - c#-4.0

I want to add a child node to an element in XmlDocument. For the life of me I can't seem to find a way to all the elements where an attribute with a known value exists without knowing the name of the element.
However I can't get the xpath working.
doc.SelectNodes(/XXXXXX[#Name='the_value_I_want'])
What goes in XXXX please?
I'm more than happy to switch this function Linq2Xml if it's easier.

doc.SelectNodes("//node()[#Name='the_value_I_want']")
or just
doc.SelectNodes("//[#Name='the_value_I_want']")

Just use *
doc.SelectNodes(/*[#Name='the_value_I_want'])
OR
doc.SelectNodes(//*[#Name='the_value_I_want'])

Related

Nightwatch.js using data attributes

I'm new to nightwatch.js. I work in QA and the developers don't want to use ids or classes for the automated tests. They want to use data-test. So for example data-test="nav-button".
Is there way to find elements and click elements using this attribute in nightwatch.js?
This is actually pretty simple. Just put the data-test in square brackets after the element type. See below for examples. In these examples, the data-test attribute is in an anchor tag.
.waitForElementVisible('a[data-test=nav-button]')
.click(a[data-test=nav-button])

Formula referencing parent doc works in computed field, not as default value

Following on from this question: Referencing parent field on document creation I'm using the formula for the default value for a name field.
IfError(#IfError(#GetDocField($ref;"ProductFamilyManager");
#GetDocField(ParentUNID;"ProductFamilyManager"));
"")
This works when it's a computed field, but not when i change it to be editable with a default value formula.
Any ideas how I can get the field populating with the default value?
The best way of doing this is to use #InheritedDocumentUniqueId. You need to enable inheritance to make that function available, but you don't actually have to inherit any of the parent values.
You should definitely not have to be using two different techniques and #IfError to get this done. And btw: did you know that #IfError is obsolete as of Domino 7?
It may not be supported but just to be sure, has the parent doc been saved before you create the response doc?
Assuming that's not the problem, the alternative is to use the "inherit field values from parent doc " option, which will pass a value from the parent doc to the response doc on creation. I may have the wording wrong but the option is on the form properties dialog in Designer.

How to change ElementTree attribute keys?

I want to change the attributes of an existing element, and not just the values, but add/remove/change the keys too. For example,
<frame_geometry name="border" has_title="false"/>
I would like to add: rounded_top_left="5" etc...
Is modifying element attributes' keys after creation possible?
If not, perhaps I could use a workaround, something like storing all the element's attributes in a temporary dictionary and then creating a new element from that +/- any desired changes?
This solution is not desirable however because the elements I need to modify have several subelements also...
I figured it out. So simple.
Add new attribute:
element.attrib['newkey'] = 'newvalue'
will add an attribute to existing element.
To remove an existing attribute:
del element.attrib['unwanted_key']
As far as modifying existing keys, I still don't know if that's possible, but with add/remove you can easily work around.
I've had success by iterating through the elements I was hoping for a .rename style function
For element in XMLData:
if element.tag = Searching:
element.tag = "NewTag"
#Now its element.NewTag

Why the OnWorkflowItemChanged is different between List and document library?

I am doing a workflow for a document library. I put a OnWorkflowItemChanged, and I want to get the value of the column which is changed. I use the workflowProperties.Item["name"] and use the afterProperties. But when I use the workflowProperties.Item["column name"], I still got the original value. When I use the afterProperties, it's NULL.
Then I make another workflow that is the same as above for a list. I can use the workflowProperties.Item["column name"] to get the new value in OnWorkflowItemChanged.
Has anyone come across this problem before? Can you give me some help?
The question seems to mix up Item with ExtendedProperties. As to why a difference is seen on a List/Document Lib, it might have something to do with versionining or perhaps the internal serialization is different. Anyway, some of my experience is outline below. I hope it may be of use:
Use the GUID (as a Guid object, not a string) to access the Before / After ExtendedProperties field. Using the Display Name in the ExtendedProperties will not work. The documentation on it is wrong. You can use SPList.Fields to go from Display Name to Column ID (Guid).
I bind all "Before" to MyWhatever_PreviousProperties and all "After" to MyWhatever_Properties, only accessing MyWhatever_[Previous]Properties after the appropriate event(s)).

How can I automatically enable content approval on a SharePoint list?

I'm trying to create a feature that both creates a list template and an instance of that list (using the <ListTemplate> and <ListInstance> elements. I would like for content approval to be turned on by default. According to the docs on ListTemplate, setting the EnableModeration attribute to TRUE should do it. However, when I try to install the solution, I get the following error:
The 'EnableModeration' attribute is
invalid - The value 'TRUE' is invalid
according to its datatype
'http://schemas.microsoft.com/sharepoint/:TrueFalseMixed'
- The Enumeration constraint failed.
A bit more searching reveals that the value accepted is actually "True", not "TRUE". That installs fine, but it seems to have no effect when the list is created - it still doesn't require content approval. Any idea what I'm doing wrong?
Edit: If anyone could even confirm for me if they've seen "True" or "TRUE" work before, that would at least narrow down my search.
Update: I've found that I can enable content approval using code in a feature receiver:
list.EnableModeration = true;
list.Update();
That's a bit of a hack, so it'd still be nice to be able to do this through the XML instead.
I ended up just using the feature receiver approach, since I just needed to move on. However, I later found that the List element used for defining your list schema also has ModeratedList and ModerationType properties that look like they probably have something to do with this. So if anyone else is having the same problem, I would recommend giving those a shot.
Does your custom list have a field of type 'ModStat' on it?
ModStat Specifies Content Approval
status. Corresponds to the
SPFieldModStat class and to the
ModStat field type that is specified
on the Field element. Value = 23.
from the SPFieldType Enumeration docs
I set ModeratedList="TRUE" ModerationType="TRUE" for List element and EnableModerate="True" for ListTemplate element . It works for me. Well it does not matter to use TRUE or True both are same.
You only have to set ModeratedList="TRUE" for List element and EnableModerate="True" for ListTemplate element. I just checked that and work fine for me. But this only will be affected for new list instances.
I had similar question - where to enable versioning and moderation from code.
In ListInstance, go to <ListTemplate> and set following attributes:
VersioningEnabled="TRUE" for versioning and EnableModeration="True" for automatic moderation.
Link: http://msdn.microsoft.com/en-us/library/ms462947.aspx

Resources