In all examples I've seen of custom configurations nobody seems to use elements to store data, e.g.
<data name="1">
<server>aServer</server>
<ip>anipaddress</ip>
</data>
Is this actually possible?
I know I can use attributes like this:
<data name="1" server="aServer" ip="anipaddress"/>
TIA
The default implementation of ConfigurationElement.DeserializeElement does not support nodes of type XmlNodeType.Text or XmlNodeType.CDATA and throws a ConfigurationErrorsException with the following error message: The configuration section cannot contain a CDATA or text element.
Thus, to store information using the element text content, override the ConfigurationElement.DeserializeElement method.
Yes you can do that.
<configuration>
<configSections>
<sectionGroup name="pageAppearanceGroup">
<section
name="pageAppearance"
type="Samples.AspNet.PageAppearanceSection"
allowLocation="true"
allowDefinition="Everywhere"/>
</sectionGroup>
</configSections>
<pageAppearanceGroup>
<pageAppearance remoteOnly="true">
<font name="TimesNewRoman" size="18"/>
<color background="000000" foreground="FFFFFF"/>
</pageAppearance>
</pageAppearanceGroup>
</configuration>
Then to access the variables
Samples.AspNet.PageAppearanceSection config = (Samples.AspNet.PageAppearanceSection)System.Configuration.ConfigurationManager.GetSection(
"pageAppearanceGroup/pageAppearance");
Response.Write("<h2>Settings in the PageAppearance Section:</h2>");
Response.Write(string.Format("RemoteOnly: {0}<br>",
config.RemoteOnly));
etc....
Check this link
http://msdn.microsoft.com/en-us/library/2tw134k3.aspx
Related
I have a HTML-field in my model.py like this:
from odoo import models, fields
class TestModel(models.model):
_name = 'test.model'
content = fields.HTML()
To display the data of my model I used <field name="content" widget='html'> in the corresponding view file.
Now I want to add predefined data, when the module is first installed.
Normally, I add data inside the datafolder with .xml files.
So I created an .xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="unique_id" model="test.model">
<field name="content">
<p>Some Text</p>
</field>
</record>
</data>
</odoo>
But I end up getting parsing errors like this:
File "/Path/to/my/odoo/installation/odoo/tools/convert.py", line 782, in convert_xml_import
relaxng.assert_(doc)
File "src/lxml/etree.pyx", line 3633, in lxml.etree._Validator.assert_
AssertionError: Element odoo has extra content: data, line 3
What am I doing wrong or do I have a complete wrong understanding of how the HTML-field works?
Any help is appreciated.
Ok, if anyone ever stumbles across this...
One has to specify the type for an HTML-field.
So instead of <field name="content"> it has to be <field name="content" type="html"> and then it works as intended.
Happy Odoo'ing!
I am trying to pass a French word from Controller to View using viewbag (The word that I try to pass is : Espèce), but inside the view when I try to affect the viewbag value's to an HTML input type text all I see is : Espéce .
In Controller
ViewBag.T = "Espèce";
In View : I used Jquery to affect the value
$("#T").val("#ViewBag.T").focus();
The HTML Input
<div>
<input type="type" id="T" value="" />
</div>
The result
Looks like an encoding issue. I'd recommend UTF-8 to ensure you get the accent marks to show up correctly.
From the Microsoft ASP.NET documentation:
To set the encoding for all pages, add a Globalization property to the
Web.config file, and then set its fileEncoding, requestEncoding, and
responseEncoding attributes, as shown in the following example:
<configuration>
<system.web>
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-US"
uiCulture="de-DE"
/>
</system.web>
</configuration>
Try the below jquery code it will work as you expected. But it may introduce an XSS vulnerability. You can refer the link.
$("#T").val($("<div/>").html("#ViewBag.T").text()).focus();
A while back, I asked a question regarding the usage of namespaces in MSXML. At first, I circumvented the whole thing with the XPath *[local-name()]-hack (see my previous post), but having a crisis of conscience I decided to do things the right way. (Doh!)
Consider the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<Root xsi:schemaLocation="http://www.foo.bar mySchema.xsd" xmlns="http://www.foo.bar" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyElement>
</MyElement>
</Root>
When I try to add these namespaces using IXMLDOMDocument3.setProperty('SelectionNamespaces', NSString);, I get the following error: "SelectionNamespaces property value is invalid. Only well-formed xmlns attributes are allowed.". When removing the namespace xsi:schemaLocation="http://www.foo.bar mySchema.xsd", everything runs smoothly. What am I doing wrong here? Is there an error in the XML? Is MSXML to blame?
xsi:schemaLocation="..." is not a namespace definition, it is an attribute of the <Root> element which is in xsi namespace.
So removing this from the list of namespaces as you did is already the solution.
Does any one know what is the exact usage of xmlns in HTML, XML files?
Edit: Why do we need this namespace? What is its usage?
The xmlns attribute has special handling, that allows the declaration of a namespace.
All names, such as tag names, in a document belong to a namespace. In the absence of the xmlns attribute all the names belong to the "no name" namespace. Hence:-
<root><item /></root>
In the above example both root and item are names in the "no name" namespace. Whereas:-
<root xmlns="urn:mydomain.com:mystuff"><item /></root>
Now root and item exist in the "urn:mydomain.com:mystuff" namespace.
The xmlns can further define additional namespaces elements of which can be distinguished from others by using an alias prefix:-
<root xmlns="urn:mydomain.com:mystuff" xmlns:a="urn:otherdomain.com:other">
<item>
<a:supplement />
</item>
</root>
In this case root and item continue to be in the "urn:mydomain.com:mystuff" namespace but a:supplement indicates that the name supplement is in the "urn:otherdomain.com:other" namespace.
What does this acheive?
The X in XML stands for eXtensible. One goal is to allow additional information to layer onto an existing document, i.e., the ability to extend the document. Consider:-
Party A create a document:-
<root>
<item />
<root>
Party B extends the document by including additional information:-
<root>
<item />
<supplement />
</root>
Later Party A adds new info to their original form of the document and just so happen to also use the name supplement in their original. We could end up with something like:-
<root>
<item />
<supplement />
<supplement />
</root>
Which supplement element belongs to which party? By using namespaces the document would look like this:-
<root xmlns="urn:mydomain.com:mystuff" xmlns:a="urn:otherdomain.com:other">
<item />
<supplement />
<a:supplement />
</root>
Now when it comes to parsing and querying the XML its clear which element belongs to whom. Namespaces elimnate the collision between what would otherwise be a global set of simple names.
The xmlns attribute declares an XML Namespace. The Namespaces in XML standard discusses this element in depth.
Namespaces are used primarily to avoid conflicts between element names when mixing XML languages. If you have a particular application that you have questions about, perhaps you could post an example.
XML namespaces help contextualize elements an attributes, among other things. It also offers a precise identification for a particular element or attribute.
For instance, the <html> element can be defined by anyone and have any meaning. However, the <html> element within the http://www.w3.org/1999/xhtml namespace is unique and refers to the XHTML.
Namespaces also prove useful when dealing with homographs, when using multiple XML languages in a single file.
In HTML, xmlns is just a talisman to make moving from and to XHTML easier. It doesn't do anything at all.
Namespaces let you reduce ambiguity when there are duplicates. You could have a <title> tag that refers to authors and <title> tag that refers to a salutation, like Mr., Mrs. etc. To differentiate, you could assign them to different namespaces.
You can also use namespaces when validating documents for conformance to a particular standard/restrictions, where the namespace would indicate to what "Schema" that the document is belonging to.
I am trying to create an element in an XML schema such that only standard (X)HTML elements can be used as children. What I've tried is this:
<xs:element name="description">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:any namespace="http://www.w3.org/1999/xhtml" />
</xs:sequence>
</xs:complexType>
</xs:element>
Of course, this doesn't work, as the following XML doesn't explicitly specify the namespace:
<description>
<p>this is a test</p>
<p>this is a <b>bold</b> test</p>
<h1>Those were the tests</h1>
</description>
Do I need to specify the namespace somewhere in the document, or can I get it in the schema?
I think you need to disable the content processing thus:
<xs:any namespace="http://www.w3.org/1999/xhtml" processContents="skip"/>
See section 5.5 in the XML Schema spec (particularly the examples)
Your schema looks ok. Note that the default value for xs:any/#processContents is strict, which means your XHTML elements will be also validated so you will need to have also an XHTML schema and import it from your schema. You can use processContents="lax" inside xs:any to specify that the validation will be applied only if there is a schema for those elements.
Your problem is in the instance where you should specify the namespace for the XHTML element. You can declare the XHTML namespace as default namespace on each element, for example
<p xmlns="http://www.w3.org/1999/xhtml">this is a test</p>
or you can declare it bound to a prefix, h for instance and then use that prefix to qualify your XHTML elements:
<description xmlns:h="http://www.w3.org/1999/xhtml">
<h:p>this is a test</h:p>
<h:p>this is a <b>bold</b> test</h:p>
<h:h1>Those were the tests</h:h1>
</description>
DTDs are not namespace aware and there namepsace declarations are just attributes, thus it is possible to declare a fixed xmlns attribute on an element to put it in a specific namespace automatically. XML Schemas are namespace aware and you cannot have a namespace declaration as a fixed attribute.
I think you really need to view this page