I am going to add a custom attribute 'custom-type' with "a" element, at the same time only allow "h1" and "a" element.
I try following codes:
$config= HTMLPurifier_Config::createDefault();
$config->set('Attr.EnableID',true);
$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'custom-type', 'Text');
$config->set('HTML.Allowed', 'h1,a[href|id|custom-type]');
$html_purifier = new \HTMLPurifier($config);
$clean_html = $html_purifier->purify($str);
It generates errors like below:
"Cannot set directive after finalization invoked on line 69 in file "
I am wondering what is wrong with above codes. Any suggestions would be appreciated.
I solved this question. It works after changing order of above codes like this:
$config= HTMLPurifier_Config::createDefault();
$config->set('Attr.EnableID',true);
$config->set('HTML.Allowed', 'h1,a[href|id|custom-type]');
$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'custom-type', 'Text');
$html_purifier = new \HTMLPurifier($config);
$clean_html = $html_purifier->purify($str);
Set rules first, then set getHTMLDefinition(true) to true to retrieve a copy of previously set rules, finally add custom attribute.
Related
How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] {">","<"});
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child) {
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
}
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
As the title says. I tried it with a String or a normal Array and it works. But when I try to pass on my 2D Array my class won't get anything. We're talking about an Array 16 width and about 50 in length.
In my XMLLoader.as class I have this:
function getConvoArray():Array
{
trace("convoArray send");
return convoArray;
}
And in my DialogueGenerator.as class I have this:
xmlLoader = new XMLLoader("ConvoLines.xml");
convoArray = xmlLoader.getConvoArray();
I've checked if the variable convoArray is filled in the XMLLoader.as class by tracing it in a for loop; it works perfectly. But then, when I try to pass it on to the DialogueGenerator.as class it seems to be empty. I cannot excess anything and Flash doesn't give me an error or a warning.
I simply have my Array in DialogueGenerator declared as this:
public var convoArray:Array;
But I tried different ways of declaring it.
Is there a solution for this? A workaround?
For loading xml I use something like this....
var fileName:String = "ConvoLines.xml";
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, LoaderComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, LoaderError);
loader.load(new URLRequest(fileName + "?rnd=" + Math.random()));
// we affix rand to prevent it from caching the file,
// you don't have to add the ? variable if you aren't worried about it
// updating smoothly
Then in the "LoaderComplete" function we just get the xml out. Hope that helps.
var convoXML:XML = new XML(event.target.data);
I need to initialized without binding.
I've tried the following. But I did not succeed
$scope.emptyRow = $scope.newsCategories[1];
$scope.newsCategories[1].Name = "yes";
$scope.emptyRow.Name = "test";
alert($scope.emptyRow.Name); // alert => test
alert($scope.newsCategories[1].Name);// alert => test
I need this :
$scope.emptyRow = $scope.newsCategories[1];
$scope.newsCategories[1].Name = "yes";
$scope.emptyRow.Name = "test";
alert($scope.emptyRow.Name); // alert => test
alert($scope.newsCategories[1].Name);// alert => yes
How to do this?
This has nothing to do with binding, but rather basic javascript.
The line: $scope.emptyRow = $scope.newsCategories[1];
is explicitly saying that you want $scope.emptyRow and $scope.newsCategories[1] to be pointing to the exact same object. Hence, when you change a child value of either (like Name), it will effect the other.
It looks like you want to be able to copy the object in question. For that you can use angular.copy(). An example use in your case would be:
$scope.emptyRow = angular.copy($scope.newsCategories[1]);
Read here for more info.
I'm facing problem in setting my record value.
I have nested record inside store like this :
- data
act_reading // I can set value of this record using -> record.set('act_reading', 'dsds');
adj_reading
act_reading_nested
- data
arr_act_colour // How can I set this record?
arr_act_rating // How can I set this record?
arr_act_ferrous // How can I set this record?
idrectype1 // How can I set this record?
adj_reading_nested
- data
arr_adj_colour
arr_adj_rating
arr_adj_ferrous
idrectype2
How can I set idrectype1 value inside act_reading_nested?
I also have to do the same thing for arr_act_colour, arr_act_rating, & arr_act_ferrous.
Thanks in Advance
Assuming record is variable holding reference to your recrd, wouldn't that work?
record.get('act_reading_nested').set('arr_act_colour','value');
record.get('act_reading_nested').idrectype1 = 'something';
Yes it would. Just checked.
From my experience with current implementation of the Store you can not :( I'm facing with such kind issue too, when I'd like to edit a non-plain Store in the GridPanel. see http://www.sencha.com/forum/showthread.php?119573-Event-beforeedit-in-EditableGridPanel&highlight=afteredit
I did not check it myself (rather found a hack workaround), but more clean way is to fix it with your own Store implementation using of Ext.override(Ext.Store, { ...}) facility.
See how I did it for 'standard' HttpProxy implementation.
Ext.override (Ext.data.HttpProxy, {
buildUrl : function (action, record) {
var ret = '';
if (window.location.pathname != '/') {
ret = window.location.pathname;
};
return ret + Ext.data.HttpProxy.superclass.buildUrl.call(this, action, record);
}
});
It requires a bit deep Extjs internal knowledge though.
I keep getting a NullReferenceException at this line UserRoot.Element("User_ID").Value = User.User_ID.ToString();
What exactly am I doing wrong?
Here's the majority of the code for that method
if (File.Exists(Path2UserDB + User.User_ID.ToString() + ".db") == false)
{
File.Create(Path2UserDB + User.User_ID.ToString() + ".db");
}
XElement UserRoot = new XElement("User");
UserRoot.Element("User_ID").Value = User.User_ID.ToString();
UserRoot.Element("Full_Name").Value = User.Full_Name;
UserRoot.Element("Gender").Value = User.Gender;
UserRoot.Element("BirthDate").Value = User.BirthDate.ToString();
UserRoot.Element("PersonType").Value = User.PersonType.ToString();
UserRoot.Element("Username").Value = User.Username;
UserRoot.Element("Password").Value = User.Password;
UserRoot.Element("Email_adddress").Value = User.Email_Address;
XDocument UserDoc = new XDocument();
UserDoc.Save(Path2UserDB + User.User_ID.ToString() + ".db");
Thanks
I know that saving Usernames and Passwords in plain text is incredibly unsafe, but this is only going to be accessed by one process that I will eventually implement strong security
The Element("User_ID") method returns an existing element named <User_ID>, if any.
Since your XML element is empty, it returns null.
You should create your XML like this:
var userDoc = new XDocument(
new XElement("User",
new XElement("User_ID", User.User_ID),
new XElement("Full_Name", User.Full_Name),
new XElement("Gender", User.Gender),
...
)
);
Alternatively, you can call the Add method to add a node to an existing element.
You are getting this error, because there is no XML element called User_ID under UserRoot to set its value. If you comment it out, you will get the same error on the next line and so on for every other Element, since you haven't added Elements with thos names. To create the tree that you want, try this:
XElement UserRoot =
new XElement("User",
new XElement("User_ID", User.User_ID.ToString()),
new XElement("Full_Name", User.Full_Name),
new XElement("Gender", User.Gender),
new XElement("BirthDate", User.BirthDate.ToString()),
new XElement("PersonType", User.PersonType.ToString()),
new XElement("Username", User.Username),
new XElement("Password", User.Password),
new XElement("Email_adddress", User.Email_Address)
);
The following MSDN link on XML Tree Creation with XElement will be of help.
You want to check if the value is null or empty before running methods on it.
if(!String.IsnullorEmpty(User.User_ID))
UserRoot.Element("User_ID").Value = User.User_ID.ToString();