I load an xml file into an Xelement. I then look for an an element named R via:
XElement elem = xmlTemplate.Descendants().Where(x => x.Name.LocalName == "R").FirstOrDefault();
I then search for the attributes EF and EX via:
elem.Attribute("EF").SetValue(txtEffective.Text);
elem.Attribute("EX").SetValue(txtExpire.Text);
but when I call xTemplate.Save(...), it does not save the udpated attributes. I have also tried:
elem.Attribute("EF").Value = txtEffective.Text;
elem.Attribute("EX").Value = txtExpire.Text;
I found out the problem, but not sure how to avoid it. When I load the XML, I am loading the two attributes in two text boxes on the form. When I change the values in the text box to update the attributes, it is updating the xml with the original values in the text box and not new ones. I wonder if this has to do with the fact that the text boxes are loaded on page load and when I click the button, it actually loads the xml again and overwrites my new values with the original values. After I did not load the values in the text box, the save worked fine.
Related
In the attached screenshot I want to read the value of title which is 'Title_6jOa'
But I'm unable to locate the element because text value is not present in highlighted area.
Any solution please.?
You should be able to locate the field by the class of the field, a CSS selector could be .x-frs-id-ivnt_Title
Then for reading the text that is typed into the field,
findElement(By.cssSelector(".x-frs-id-ivnt_Title")).getAttribute("value")
If the css selector .x-frs-id-ivnt_Title can't find the expected text box, try below xpath:
findElement(By.xpath("//tr[td[contains(., 'Title')]]/td/input")).getAttribute("value")
Please check the CSS selector and xpath manually in browser DevTool before change code.
Input Field Text values will not be be persisted in the Input Tag in Dev Tool.So,we cannot not use getText() Method and it can be extracted using the getAttribute() method as below or JavaScriptExecutor can be used (Using Selenium Web Driver to retrieve value of a HTML input)
Steps:
Identity the text field Web Element using any one of the unique locator
Use the getAttribute Method to get the value
Code :
WebElement titleInputElement=driver.findElement(By.xpath("//input[contains(#class,'x-frs-id-ivnt_Title')]"));
String value=titleInputElement.getAttribute("value");
#yong , #Subburaj Sorry tried yours way too, but getting no value.
Getting the value in below way perfectly.
Steps:
Double click in the text field. To get text selected.
Then copy the text to clipboard using Keyboard key ctrl+c
Copy the text
And Then the final step is reading the text from clipboard by below line of code in c#.
string clipboardExpectedText = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text);
I am currently serializing a List<SomeObject> to an XML file, which works fine...
In the SomeObject properties, one of them is a string that contains multiple items delimited by the Environment.NewLine character.
When i open the XML file using Excel, some of the cells containing that property, with a few items in them, show up fine (WrapText is set) and yet some others with more items just show up as a string of # signs.
Is there a way to properly show the property's contents with the new lines in there so that Excel displays them correctly, while retaining the original XML? I mean, is this a Serialization issue, or a display setting in Excel i've missed?
The only way i was able to get the text to display properly, was to highlight the entire column in excel, and set the format to Custom -> 0 ... otherwise, in its original format of Text, i only get # signs...
Did you check to see if the XML document was formatted correctly? Because infinite #################### in a cell usually means something is either formatted incorrectly or Excel doesn't understand its type. For example, Excel can't do negative time so subtracting Earlier Date from Later Date = infinite #######. If you hover your mouse over the cell, it may tell you what the issue is.
I have a word template which has a content control placeholder to hold rich text data. The data comes from a sharepoint list (rich text field) and may also include tables in it.
On checking the data from sharepoint list I found it returns me a HTML formatted data. I wish to place this data in the content placeholder with proper formatting.
For example if the data returned is HTML table ( format) I want a table to be created with data populated. Is there any method available to place the data in content control.
I found that third party tool converter at http://html2openxml.codeplex.com/ which is available for conversion, however this appends data to MainDocumentPart not to content control.
Please guide. Thanks in advance.
You could try to use WordDocGenerator, which uses content controls. Then combine it with html2openxml, as discussed here. However, I find the formatting in some cases becomes terrible after adding the html content into your content control--one example is when inserting lists, the bullet points goes out of view when you open the document. I have not tried adding a whole table into a content control.
My application is a form based application, having multiple textboxes that can be filled. Some textboxes however is optional and a checkbox is included to toggle if it should be included.
Now I would like to save the progress of the form so it can be opened later for further editing. I am saving this file as an .xml. Saving the textboxes I have no problem with, but what is the best way to save the state of the checkboxes to the .xml file, so it can be loaded later?
I can simply use - string s = Bool.ToString();.
It does work but when working with a lot of checkboxes it can become a long process. I have a class that handles the saving of the .xml file. Is there a way to add more then one checkbox to a list then parse the "true/false" value to the class as an array of Bool[]?
Checkbox-state is nothing else than an Boolean? -> Nullable bool. You can simple serialize it using an xmlserializer or write it manually to the file:
string s = checked.ToString();
and to parse it:
bool checked = Boolean.Parse(s)
I tried xtraTreeList's exporttoXML property. But the generated xml does not contain any information of the node like ID or is Chcked etc and just the name and parentID. Is there any other export property which will give all the information ?
TreeList.ExportToXml(String) Method exports the tree list's data
to the specified file as XML not the layout. You can use
TreeList.SaveLayoutToXml(String) Method to save the layout and
restore it by using TreeList.RestoreLayoutFromXml(String) Method.
Code snippet:
string fileName = "c:\\TreeListLayout.xml";
treeList1.SaveLayoutToXml(fileName);
treeList2.DataSource = treeList1.DataSource;
treeList2.RestoreLayoutFromXml(fileName);
Go Through DevExpress Example How to preserve the expanded state of TreeList nodes when refreshing data and the following reference links.
Ref:
How to load and save the layout of a TreeList by code
SearchResult
Hope this help..