I want to build a Polymer 2.0 custom element DOM tree, but I want to just populate the children (the slots) based on the tag type of each child, so when I'm writing the HTML to use my custom elements don't want to write:
<group>
<title slot="title">admins</title>
<description slot="description">some description</description>
<users slot="users">
<user slot="user">
<name slot="name">Amy</name>
<dept slot="dept">Widgets</dept>
<phone slot="phone">1234</phone>
</user>
<user slot="user">
<name slot="name">Bill</name>
<dept slot="dept">Sprockets</dept>
<phone slot="phone">5678</phone>
</user>
<user slot="user">
<name slot="name">Chris</name>
<dept slot="dept">Rachets</dept>
<phone slot="phone">1357</phone>
</user>
</users>
</group>
This should work using named slots in Polymer 2.0, but you can see it's very cumbersome and redundant if you have a deep tree where every level has several properties.
What I really want to do instead is just write:
<group>
<title>admins</title>
<description>some description</description>
<users>
<user>
<name>Amy</name>
<dept>Widgets</dept>
<phone>1234</phone>
</user>
<user>
<name>Bill</name>
<dept>Sprockets</dept>
<phone>5678</phone>
</user>
<user>
<name>Chris</name>
<dept>Rachets</dept>
<phone>1357</phone>
</user>
</users>
</group>
which is essentially just XML. This seems much easier to work with than the first example to me. As you can see with the named slots, as the tree gets deeper it gets very crowded and messy.
So my question is how can I do the latter example in Polymer 2.0? Is it even possible? It seems to me that this would be a prime use case for Polymer so there really should be a way to achieve it. The closest I found was this web page, but it doesn't really do what I want cause you are limited to one "default" slot per custom element template:
https://developers.google.com/web/fundamentals/getting-started/primers/shadowdom#slots
I'm not really sure what are you trying to archieve here, you sure you don't really want dom-repeat instead? It looks to me you just want to list some elements based on the XML you posted.
Related
I am writing a couple of man pages in DocBook. I would also like to convert them to HTML for display on the web. How can I insert a link from one man page to another, such that it appears in man as target(1) but appears on the web as a hyperlink to the other man page, which has also been converted to a separate HTML file in the same directory?
I think I have figured this out. You should use a <citerefentry/> in the document, which appears as expected in a man page. It isn't hyperlinked in a HTML document unless you provide a method for generating the target URL, which you do in a customisation layer.
Here is an example document snippet for the "See Also" section in a man page:
<refsect1 id="seealso">
<title>See Also</title>
<simplelist type="inline">
<member><citerefentry><refentrytitle>grep</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
<member><citerefentry><refentrytitle>awk</refentrytitle><manvolnum>1P</manvolnum></citerefentry></member>
</simplelist>
</refsect1>
Coupled with this customisation template (saved as custom.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Ignore spaces between elements (without this, the URL is "grep .html" -->
<xsl:strip-space elements="*"/>
<!-- Turn citerefentry elements into HTML links -->
<xsl:param name="citerefentry.link" select="1"/>
<!-- Code to generate the URL for a given citerefentry element -->
<xsl:template name="generate.citerefentry.link">
<xsl:value-of select="refentrytitle"/>
<xsl:text>.html</xsl:text>
</xsl:template>
</xsl:stylesheet>
Using the xmlto program to process the DocBook XML, specifying the customisation layer for HTML:
$ xmlto man input.xml
$ xmlto html-nochunks -m custom.xsl input.xml
In a manpage, this produces:
SEE ALSO
grep(1), awk(1P)
And in HTML it produces this: (all the <span> elements have been removed for clarity)
<h2>See Also</h2>
grep(1), awk(1)
The actual URLs generated can be adjusted by editing the content of the generate.citerefentry.link template in custom.xsl. The example above just uses the value of the <refentrytitle> from the DocBook XML and appends ".html" to it.
I have following XML to parse in SQL Server 2008
<Root>
<Document>
<Body>
<Component>
</Component>
</Body>
</Document>
</Root>
I want to retrieve all the <Component> tags in my xml, the issue is that <Document> tag at times might not come, Hence my xpath query of (root/document/body) won't work. Is there way I can get all <Component> tags irrespective of presence of <Document> tag?
You could always use an XPath query of
//component
to get all <component> elements in your entire document - no matter where they are and what other tags there are around it
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'm using the GGeoXml object to overlay KML on an embedded Google Map. I need to customize the popup balloon for placemarks, so I'm trying to use the <BalloonStyle> element:
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="http://earth.google.com/kml/2.0">
<name>Concessions</name>
<Style id="masterPolyStyle">
...
<BalloonStyle>
<text>
<![CDATA[
<h6>Concession</h6>
<h4>$[name]</h4>
<p>$[description]</p>
]]>
</text>
<displayMode>default</displayMode>
<bgColor>DDA39B81</bgColor>
</BalloonStyle>
</Style>
...
</Document>
This works as expected in Google Earth, but the embedded map API appears to ignore this altogether. I suppose I could just leave out the <name> element altogether and just put everything in HTML inside the <description> element, but I'd like to be able to take advantage of the <ExtendedData> element to display custom data in a structured way.
This is now documented here (2009/04):
http://code.google.com/apis/kml/documentation/kmlelementsinmaps.html
< BalloonStyle > no
(When did you ask this ? This forum/service needs a big fat DATE on each question, with a year in it :-) )
2$c,
*pike
No, like you have mentioned, html in the description is the only way I know that you can control the style of balloons through kml/georss feed.
Actually, the document referenced above (http://code.google.com/apis/kml/documentation/kmlelementsinmaps.html) must have changed, b/c now it says:
<BalloonStyle> partially only <text>
is supported
My problem is that the <text> seems to work for one KML file, but not another. The one that works for has polygon placemarkers, the other has points represented by icons - I wonder if that is why...