I need to set up infopath screentip programmatically in infopath code behind. I read something about this that it is impossible but, i made something like this:
XPathNavigator field1 = MainDataSource.CreateNavigator().SelectSingleNode(xpath1, NamespaceManager);
XPathNavigator field2 = MainDataSource.CreateNavigator().SelectSingleNode(xpath2, NamespaceManager);
if (field1.Value.ToString() == "none")
{
this.Errors.Add(field2, "XXX", "XXxxxXX", "xxXXxxXX");
}
but still i change the field to "cannot be blank" any clue ?
I faced the exact same problem like you and didn't really find an easy and clean solution. I had to check if an IBAN was entered correctly. Working with extra fields and methods is not clean enough for me so I went and tried it through the Errors-property, which you say doesn't work. Here's the code I used:
XPathNavigator navigator = MainDataSource.CreateNavigator();
XPathNavigator ibanField = navigator.SelectSingleNode("/my:.../my:.../my:FldIban", NamespaceManager);
Errors.Add(ibanField , "Invalid IBAN", "The given IBAN is not formatted correctly");
Hope this helps anyway, it did for me. :)
I created button and special field with hide when value = true , and show when is true.
public void CTRL32_7_Clicked(object sender, ClickedEventArgs e)
{
// XPathNavigator test = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field11", NamespaceManager);
XPathNavigator test2 = MainDataSource.CreateNavigator().SelectSingleNode("my:myFields/my:buttonSet", NamespaceManager);
if (test2.Value == "FALSE")
{
test2.SetValue("TRUE");
}
else
{
test2.SetValue("FALSE");
}
XPathNavigator tooltip = MainDataSource.CreateNavigator().SelectSingleNode("my:myFields/my:tooltip", NamespaceManager);
tooltip.SetValue("Custom Tooltip DEMO");
}
Related
I need to create a complete IHTMLDocument2 document so I end up with this snippet which works. However, the URL property seems to be ignored all the times.
string page = "my HTML code in string";
IHTMLDocument2 doc2 = (IHTMLDocument2)new HTMLDocument();
doc2.url = "www.stackoverflow.com";
doc2.write(new object[] { page });
doc2.close();
while (doc2.body == null)
Application.DoEvents();
Now doc2.url is always "about:blank". How can I set this URL property?
Thank you in advance,
I'm trying to get all languages from Google Translate. When I Open Developer Tools and click one of the language when all languages are popped (when arrow clicked), It gives //*[#id=':7']/div/text() for Arabic, but it returns null when I try to get node:
async Task AddLanguages()
{
try
{
// //*[#id=":6"]/div/text()
HtmlDocument document = new HtmlDocument();
document.LoadHtml(html);
for (int i = 6; i <= 9; i++)
{
//*[#id=":6"]/div/text() //*[#id=":6"]/div/div
Debug.WriteLine(i);
var element = document.DocumentNode.SelectSingleNode("//*[#id=':7']/div/text()");
Trace.WriteLine(element == null, "Element is null");
}
}
catch (Exception e)
{
this.ShowMessageAsync("Hata!", "Dilleri yüklerken hata ortaya çıktı.");
}
}
Element is null: True outputs all the times ( I was trying to use for loop to loop through languages but, it doesnt even work for single one!)
I guess your xpath is wrong. You can try something like:
string Url = "https://translate.google.com/";
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(Url);
var arabic = doc.DocumentNode.Descendants("div").FirstOrDefault(_ => _.ChildNodes.Any(node => node.Name.Equals("#text") && node.InnerText.Equals("Arabic")));
Since I can't comment yet...Have you tried clicking on the dropdwon first before looking for the elements?
Clicking on //*[#id='gt-sl-gms'] or it's inner div would make the elements visible..
That should work..
Anyway, I can't make $x work for the console in google chrome. I'm getting an Uncaught Type Error currently. Not sure if that has to do with anything..
Edit: Oh wait i think I know your problem..upon closer inspection of the element, it seems that the element (div) has another div before the text. so try /*[#id=':7']/div/text()[2]
I have an XML file that collects information with Button_Click, so it starts off empty.
XML Sample
<marina>
<dockone>
</dockone>
<docktwo>
</docktwo>
</marina>
When I submit information from a textbox, a new XmlNode is created called slipone, and another XmlNode called reg is nested within that.
XML Sample 2
<marina>
<dockone>
<slipone>
<reg>12345</reg>
<slipone>
</dockone>
<docktwo>
</docktwo>
</marina>
I have attempted to create an if/else statement that will add a new XmlNode called sliptwo, with reg still nested within it, if slipone already has text, like so:
<marina>
<dockone>
<slipone>
<reg>12345</reg>
<slipone>
<sliptwo>
<reg>67890</reg>
<sliptwo>
</dockone>
<docktwo>
</docktwo>
</marina>
However the closest I have gotten is another XMlnode is still created, however it labels itself as slipone, and I am not sure what I am doing wrong:
<marina>
<dockone>
<slipone>
<reg>12345</reg>
<slipone>
<slipone>
<reg>67890</reg>
<slipone>
</dockone>
<docktwo>
</docktwo>
</marina>
This is an example of what I have been playing around with. Ignore the operators as I have resorted to trial and error but still have gotten nowhere. Please help!
C# Example
XmlDocument XmlDocObj1 = new XmlDocument();
XmlDocObj1.Load(Server.MapPath("~/App_Data/SlipData.xml"));
XmlNode rootnode1 = XmlDocObj1.SelectSingleNode("marina/dockone");
XmlNode dockone = rootnode1.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "slipone", ""));
XmlNode docktwo = rootnode1.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "sliptwo", ""));
XmlNode dockthree = rootnode1.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "slipthree", ""));
if (regfinal.Text != dockone.InnerText)
{
dockone.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "Reg", "")).InnerText = regfinal.Text;
XmlDocObj1.Save(Server.MapPath("/App_Data/SlipData.xml"));
}
else if (regfinal.Text == dockone.InnerText)
{
docktwo.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "Reg", "")).InnerText = regfinal.Text;
XmlDocObj1.Save(Server.MapPath("/App_Data/SlipData.xml"));
}
Your logic isn't going to do what I think you are saying since the only time (regfinal.Text != dockone.InnerText) will evaluate to false is when you enter nothing in your text control.
I believe you might mean to say if dockone exists then create another node called docktwo. This will require you to change your logic.
Some very simple code to get you a bit farther down the path. Not intended to be perfect or solve all problems...
private void button1_Click(object sender, EventArgs e)
{
XmlDocument XmlDocObj1 = new XmlDocument();
XmlDocObj1.Load(AppDomain.CurrentDomain.BaseDirectory.ToString()+"test.xml");
XmlNode rootnode1 = XmlDocObj1.SelectSingleNode("marina/dockone");
XmlNode dockone = rootnode1.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "slipone", ""));
XmlNode docktwo = rootnode1.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "sliptwo", ""));
XmlNode dockthree = rootnode1.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "slipthree", ""));
//jsh: old logic
//if (textBox1.Text != dockone.InnerText)
//new logic to test whether we have already created the dockone node which should only occur once
//you already have the logic for selecting the dockone node above...now just test if you already have it.
//NOTE: you may actually want a switch statement given that you avhe dockone, docktwo, and dockthree or at least another
// if statement to see if docktwo has been created and thus creaste dockthree.
if (rootnode1 == null )
{
dockone.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "Reg", "")).InnerText = textBox1.Text;
XmlDocObj1.Save(AppDomain.CurrentDomain.BaseDirectory.ToString() + "test.xml");
}
//else if (textBox1.Text == dockone.InnerText) jsh: old logic
else
{
docktwo.AppendChild(XmlDocObj1.CreateNode(XmlNodeType.Element, "Reg", "")).InnerText = textBox1.Text;
XmlDocObj1.Save(AppDomain.CurrentDomain.BaseDirectory.ToString() + "test.xml");
}
}
I'm looking to get the *.aspx page name from the parent of an IHTMLElement. I started looking through the attributes on an IHTMLElement, and the document property looked promising.
Do I just need to cast as follows?
IHTMLElement elem;
elem = getElement(args);
IHTMLElement2 dom = (IHTMLElement2)elem.document;
string aspx = dom.<something?>;
That doesn't appear to work, but I feel like I'm on the right track. Ideas?
HTMLDocument doc = somedoc;
Regex pullASPX = new Regex(#"(?<=\/)[^//]*?(?=\.aspx)");
if (elem != null && !doc.url.Contains("default.aspx"))
{
EchoAbstraction.page = pullASPX.Match(doc.url).Value;
EchoAbstraction.tag = tagName;
EchoAbstraction.id = elem.id;
}
This is how I ended up doing it. I had found the ID in the dom already, so I just pulled the current doc page and parsed the URL.
I keep getting errors with this, and can't see what I'm doing wrong.
Here's the code
private void _FixSave_Offline_Load(object sender, EventArgs e)
{
System.Xml.XmlDocument NewGame = new System.Xml.XmlDocument();
NewGame.Load(Application.StartupPath + "//Files//Checks_Offline.xml");
foreach (System.Xml.XmlNode nameNode in NewGame.SelectNodes("//Games//NewGame"))
{
listView1.Items.Add(nameNode.Attributes["Name"].InnerText);
}
}
And here is the XML Layout
<Games>
<NewGame>
<Name></Name>
<Check></Check>
<Static></Static>
<Location></Location>
<Start></Start>
<Length></Length>
<FoundBy></FoundBy>
<Verified></Verified>
</NewGame>
Here's is the error I keep getting
and visual studio highlights the following code:
listView1.Items.Add(nameNode.Attributes["Name"].InnerText);
I've tried using not only "//" but also "/" so anything that will fix this will be more than welcome, b/c I can't for the life of me see what I'm doing wrong.
At a glance, you're looking for an attribute with the name of "Name", but there are no attributes on any of the XML elements in your example.
I believe you want the content of the Name node:
foreach (System.Xml.XmlNode nameNode in NewGame.SelectNodes("//Games//NewGame/Name"))
{
listView1.Items.Add(nameNode.Value);
}
You might have to play with the XPath expression a bit, depending on the actual structure of your XML document.
I couldn't see your XML example for some reason, but make sure you are distinguishing between Elements and Attributes
Also, make sure that the attribute/element is spelled "Name" exactly. I believe it is case sensitive.
--
Edit: Now I am able to view your XML, it appears that "Name" is actually an element, rather than an attribute.
Try using the Item property, or the Value property instead of nameNode.Attributes.
I got it to work. Turns out that I the error was due to virtuallist = true. Tim I modified your code above just a little to get the result I wanted. Here's the code for anyone to use for future ref.
private void _FixSave_Offline_Load(object sender, EventArgs e)
{
System.Xml.XmlDocument NewGame = new System.Xml.XmlDocument();
NewGame.Load(Application.StartupPath + "//Files//Checks_Offline.xml");
foreach (System.Xml.XmlNode nameNode in NewGame.SelectNodes("//Games//NewGame/Name"))
{
listView1.Items.Add(nameNode.InnerText);
}
}
And here's a quick screenshot for the given result.
Hope this helps others as well. Thanks to the above people who commented me on this, and big thanks to Tim.