vinothkumar's Profile

1820
Points

Questions
44

Answers
117

  •      Use clojure.data.zip.xml which is used to be clojure-contrib.zip-filter.xml prior to Clojure 1.3.

    file: myfile.xml

    <songs>
      <track id="t1"><name>Track one</name></track>
      <track id="t2"><name>Track two</name></track>
    </songs>
    

    code:

    ; Clojure 1.3
    (ns example
      (:use [clojure.data.zip.xml :only (attr text xml->)]) ; dep: see below
      (:require [clojure.xml :as xml]
              [clojure.zip :as zip]))
     
    (def xml (xml/parse "myfile.xml"))
    (def zipped (zip/xml-zip xml))
    (xml-> zipped :track :name text)     ; ("Track one" "Track two")
    (xml-> zipped :track (attr :id))     ; ("t1" "t2")
    

         The user want to pull in a dependency on data.zip to get this nice read/filter functionality by unfortunate.

    [org.clojure/data.zip "0.1.1"]
    

         Then for docs for data.zip.xml. The relative small source file here to see what is possible.

    • 1034 views
    • 10 answers
    • 0 votes
  • Asked on January 12, 2019 in XML.

    Embedding SVGs into another SVG:

    <image x="10" y="20" width="80" height="80" xlink:href="image.svg" />
    

         After that the embedded SVG will takes a rectangular shape with provided dimensions.

    Simply to say that if our embedded SVG is a circle or some other shape than a square, then it will become a square with transparency. Thus, the mouse events can get trapped into that embeded square and will not reach the parent SVG.

         To fill a shape, either a circle, a square or even a path is a good approach to using a pattern

    <defs>
      <pattern id="pat" x="0" y="0" width="500" height="500" patternUnits="userSpaceOnUse">
        <image x="0" y="0" width="500" height="500" xlink:href="images/mysvg.svg"></image>
      </pattern>
    </defs>
    

         Then use the pattern like given  below,

    <circle cx="0" cy="0" r="250" fill="url(#pat)"></circle>
    

         At current, the mouse events will not get stuck into transparent image squares.

    • 535 views
    • 6 answers
    • 0 votes
  •      To use namespaces, LINQ to XML will makes it by simple:

    XNamespace ab = "http://whatever-the-url-is";
    XElement tempElement = doc.Descendants(ab + "test").FirstOrDefault();
    

         Search for an xmlns:ab=… section in the document to find that which namespace URI “ab” will refers to.

    • 1528 views
    • 7 answers
    • 0 votes
  •      The alternative way is the remove function. So call the tree’s remove method and pass it a subelement to remove.

    import lxml.etree as et
    xml="""
    <groceries>
      <fruit state="rotten">apple</fruit>
      <fruit state="fresh">pear</fruit>
      <punnet>
        <fruit state="rotten">strawberry</fruit>
        <fruit state="fresh">blueberry</fruit>
      </punnet>
      <fruit state="fresh">starfruit</fruit>
      <fruit state="rotten">mango</fruit>
      <fruit state="fresh">peach</fruit>
    </groceries>
    """
     
    tree=et.fromstring(xml)
     
    for bad in tree.xpath("//fruit[@state='rotten']"):
        bad.getparent().remove(bad)
     
    print et.tostring(tree, pretty_print=True)
    

    Result:

    <groceries>
      <fruit state="fresh">pear</fruit>
      <fruit state="fresh">starfruit</fruit>
      <fruit state="fresh">peach</fruit>
    </groceries>
    
    • 1351 views
    • 8 answers
    • 0 votes
  • Converting object to xml:

    public static string Serialize(object dataToSerialize)
    {
       if(dataToSerialize==null) return null;
     
       using (StringWriter stringwriter = new System.IO.StringWriter())
       {
          var serializer = new XmlSerializer(dataToSerialize.GetType());
          serializer.Serialize(stringwriter, dataToSerialize);
          return stringwriter.ToString();
       }
    }
     
    public static T Deserialize<T>(string xmlText)
    {
       if(String.IsNullOrWhiteSpace(xmlText)) return default(T);
     
       using (StringReader stringReader = new System.IO.StringReader(xmlText))
       {
          var serializer = new XmlSerializer(typeof(T));
          return (T)serializer.Deserialize(stringReader);
       }
    }
    
    • 541 views
    • 9 answers
    • 0 votes
  • To create a custom View by inflating a layout:

         Create a Compound Control first. Then create a subclass of RelativeLayout, add all the components in code and in the constructor we can read the attributes passed in from the XML. Then we can pass that attribute to our title TextView.

    • 451 views
    • 7 answers
    • 0 votes
  • Try the allternative code:

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:background="#000"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/header"
        app:itemTextColor="your color"
        app:menu="@menu/drawer" />
    
    • 578 views
    • 6 answers
    • 0 votes
  • To convert dom to a string try the code:

    DocumentBuilderFactory domFact = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = domFact.newDocumentBuilder();
    Document doc = builder.parse(st);
    DOMSource domSource = new DOMSource(doc);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.transform(domSource, result);
    System.out.println("XML IN String format is: \n" + writer.toString());
    
    • 421 views
    • 6 answers
    • 0 votes
  •      Use CDATA with \n if refering to res strings,

    <string name="about">
        <![CDATA[
    Author: Sergio Abreu\n
    http://sites.sitesbr.net
      ]]>
    </string>
    
    • 438 views
    • 7 answers
    • 0 votes
  •      To add a specific amount of space simply use Space or View. For example , for 30 vertical density pixels,

    <Space
      android:layout_width="1dp"
      android:layout_height="30dp"/>
    

         If user need a flexible space-filler, then use View between items in a LinearLayout:

    <View
      android:layout_width="1dp"
      android:layout_height="match_parent"
      android:layout_weight="1"/>
    

         else

    <View
      android:layout_width="1dp"
      android:layout_height="0dp"
      android:layout_weight="1"/>
    

         It will works for more layouts for API 14 and later, except the widgets that use FrameLayout instead of that.

    • 394 views
    • 7 answers
    • 0 votes