Adding an invisible document name in XSLT or HTML

I have this XSLT document that has a file name. However for archiving purposes we want the file name to be displayed somewhere else within the code.

Now I used to do this like this:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    sample-xml=".\DOCUMENTNAME.xml"
    xmlns:v="urn:schemas-microsoft-com:vml"
    xmlns:o="urn:schemas-microsoft-com:office:office">

However we want to get rid of this solution due to new working methods. Now I was wondering if I could place this (literally just the word DOCUMENTNAME) somewhere within the XSL or within the HTML wrapped within it, in a way that it is not visible.

We add this code to a database, through a validator that looks for the documentname and checks for a match. And as only the contents of the code is placed on the database its easier to check back from the database what documentname was uploaded. However this documentname should not be visible in an HTML output.

Remove Node from XML file

I would like to remove CommentsCorrections node from my xml file. I used the ElementTree XML API for removing the node. I don’t know why my python code is not working, following are examples of python and xml.

Python:

import xml.etree.ElementTree as ET 
tree = ET.parse("pubmed_result.xml")
root = tree.getroot()
for CommentsCorrections in root.findall('CommentsCorrections'):
     tree.remove(CommentsCorrections) 
tree.write("Scheduler.xml")

XML:

<CommentsCorrectionsList>
  <CommentsCorrections RefType="Cites">
    <RefSource>Clin Infect Dis. 2005 Nov 1;41(9):1254-60</RefSource>
    <PMID Version="1">16206099</PMID>
  </CommentsCorrections>
  <CommentsCorrections RefType="Cites">
    <RefSource>J Antimicrob Chemother. 1998 Jun;41 Suppl D:7-11</RefSource>
    <PMID Version="1">9688447</PMID>
  </CommentsCorrections>
  <CommentsCorrections RefType="Cites">
    <RefSource>J Antimicrob Chemother. 2008 Mar;61(3):721-8</RefSource>
    <PMID Version="1">18218645</PMID>
  </CommentsCorrections>
  <CommentsCorrections RefType="Cites">
    <RefSource>Infection. 1987;15 Suppl 5:S248-53</RefSource>
    <PMID Version="1">3325435</PMID>
  </CommentsCorrections>
  <CommentsCorrections RefType="Cites">
    <RefSource>N Engl J Med. 2005 Sep 8;353(10):988-98</RefSource>
    <PMID Version="1">16148284</PMID>
  </CommentsCorrections>
</CommentsCorrectionsList>

How to return xml data in postgresql

I am working on postgresql function where i want to return a xml.

 CREATE OR REPLACE FUNCTION schema.func_name(
    ws_queue_array character varying DEFAULT NULL::character(1),
    OUT ws_out_xml_data xml)
          RETURNS xml

I am creating an xml using xml function in postgreql but I am not sure how will I return that xml.

SELECT  XMLELEMENT (NAME "name",                 
                   XMLAGG (XMLELEMENT(NAME "var1",                           
                             XMLATTRIBUTES (                                    
                          c_name        AS "c name",                         
                          c_id  AS "c ID"))                         
                     ORDER BY c_id ASC))              
                        INTO OUT_XML_DATA;

How do i return this OUT_XML_DATA?

Alpakka : how to deserialize xml to objects – Is there a more concise pattern for deserializers?

I have complex XML data (it might contain a lot of data and could have more than 15GB) which has a sophisticated nature with a deep structure. We need stream processing for our huge XML. Using the new Alpakka library is our first choice since it is a promising solution.

There are outdated threads on scala-xml serialization and other Scala libraries, but we need to process huge amounts of XML as event streams.

In order to simplify things let’s consider that we have a PurchaseOrder (XML comes from this page).

<?xml version="1.0"?>  
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">  
  <Address Type="Shipping">  
    <Name>Ellen Adams</Name>  
    <Street>123 Maple Street</Street>  
    <City>Mill Valley</City>  
    <State>CA</State>  
    <Zip>10999</Zip>  
    <Country>USA</Country>  
  </Address>  
  <Address Type="Billing">  
    <Name>Tai Yee</Name>  
    <Street>8 Oak Avenue</Street>  
    <City>Old Town</City>  
    <State>PA</State>  
    <Zip>95819</Zip>  
    <Country>USA</Country>  
  </Address>  
  <DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>  
  <Items>  
    <Item PartNumber="872-AA">  
      <ProductName>Lawnmower</ProductName>  
      <Quantity>1</Quantity>  
      <USPrice>148.95</USPrice>  
      <Comment>Confirm this is electric</Comment>  
    </Item>  
    <Item PartNumber="926-AA">  
      <ProductName>Baby Monitor</ProductName>  
      <Quantity>2</Quantity>  
      <USPrice>39.98</USPrice>  
      <ShipDate>1999-05-21</ShipDate>  
    </Item>  
  </Items>  
</PurchaseOrder>  

I am trying to stream all Item‘s from XML and deserialize them. Be aware of fact that, the same tags might appear on the different levels.
Moreover, the elements/attributes inside Item can appear in arbitrary order.
An approach, which I see (mostly based on Alpakka’s XmlProcessingTest – does anyone can suggest better references?), might look like the following:

import akka.actor.ActorSystem
import akka.stream.alpakka.xml.scaladsl.XmlParsing
import akka.stream.alpakka.xml.{Characters, EndElement, ParseEvent, StartElement}
import akka.stream.scaladsl._
import akka.stream.{ActorMaterializer, IOResult}
import scala.collection.mutable
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import akka.util.ByteString

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.alpakka.xml.{EndElement, ParseEvent, StartElement}

import scala.collection.mutable

trait Builder[T] {
  def build(): T
}

case class Item(partNumber: String)

object Item {
  def apply(builder: ItemBuilder,
            path: mutable.Stack[String]): PartialFunction[ParseEvent, Unit] = {
    case elem @ StartElement("Item", _, _, _, _) =>
      val partNumber = elem.findAttribute("PartNumber").map(_.value).getOrElse("")
      path.push(s"Item")
      builder.partNumber = partNumber
    case EndElement("Item") =>
      path.pop()
  }
}

class ItemBuilder() extends Builder[Item] {
  var partNumber = ""

  override def build(): Item =
    Item(
      partNumber = partNumber
    )

  def reset(): Unit = {
    partNumber = ""
  }
}


implicit val system = ActorSystem()
implicit val mat = ActorMaterializer()

val path: mutable.Stack[String] = new mutable.Stack[String]()

val xml =
  """<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
    |<Address Type="Shipping">
    |  <Name>Ellen Adams</Name>
    |  <Street>123 Maple Street</Street>
    |  <City>Mill Valley</City>
    |  <State>CA</State>
    |  <Zip>10999</Zip>
    |  <Country>USA</Country>
    |</Address>
    |<Address Type="Billing">
    |  <Name>Tai Yee</Name>
    |  <Street>8 Oak Avenue</Street>
    |  <City>Old Town</City>
    |  <State>PA</State>
    |  <Zip>95819</Zip>
    |  <Country>USA</Country>
    |</Address>
    |<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
    |<Items>
    |  <Item PartNumber="872-AA">
    |    <ProductName>Lawnmower</ProductName>
    |    <Quantity>1</Quantity>
    |    <USPrice>148.95</USPrice>
    |    <Comment>Confirm this is electric</Comment>
    |  </Item>
    |  <Item PartNumber="926-AA">
    |    <ProductName>Baby Monitor</ProductName>
    |    <Quantity>2</Quantity>
    |    <USPrice>39.98</USPrice>
    |    <ShipDate>1999-05-21</ShipDate>
    |  </Item>
    |</Items>
    |</PurchaseOrder>""".stripMargin

val documentStream = Source.single(xml)

val builder = new ItemBuilder()

val default: PartialFunction[ParseEvent, Unit] = {
  case Characters(any) =>
  case StartElement(localName, _, _, _, _) =>
    path.push(localName)
  case EndElement(localName) =>
    path.pop()
  case any =>
}

val handle: PartialFunction[ParseEvent, Unit] = Item(builder, path) orElse
  default

val source: Source[Item, akka.NotUsed] = documentStream
  .map(ByteString(_))
  .via(XmlParsing.parser)
  .splitWhen(_ match {
    case StartElement("Item", _, _, _, _) =>
      true
    case _ =>
      false
  })
  .fold[ItemBuilder](new ItemBuilder()) {
  case (_, parseEvent) =>
    handle(parseEvent)
    builder
}
  .map { builder: ItemBuilder =>
    val item = builder.build()
    builder.reset()
    item
  }
  .concatSubstreams
  .filterNot(_.partNumber.isEmpty)

val resultFuture: Future[Seq[Item]] = source
  .runWith(Sink.seq)

val result: Seq[Item] = Await.result(resultFuture, 5.seconds)

println("items : " + result)
println("END")

The example is posted on Scastie

This approach requires a lot of handlers for each tag (val handle: PartialFunction) which might be error prone and too fragile.

I am wondering how to handle ParseEvent in a more concise way and combine them into the required Item objects. Any suggestion how to avoid a boilerplate code? Is there a more concise pattern for deserializers?

How to run two different animations on recyclerView consecutively?

I have a horizontal recyclerView, I want to animate it (by sliding right and then left) when the activity is first opened.

So I do this in onCreate:

final Animation slideRight = AnimationUtils.loadAnimation(this, R.anim.slide_right);
        slideRight.setDuration(200);

        final Animation slideLeft = AnimationUtils.loadAnimation(this, R.anim.slide_left);
        slideLeft.setDuration(200);

        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.startAnimation(slideRight);
        recyclerView.startAnimation(slideLeft);

but seems like only the right slide works

here are my anims:

left slide

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="200"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>

right slide

<translate
    android:duration="200"
    android:fromXDelta="100%"
    android:fromYDelta="0%"
    android:toXDelta="0%"
    android:toYDelta="0%" />

what am I doing wrong?

EDIT: how is this related to proposed duplicate?

how to remove or replace specific chars are between two xml tags [linux, python, lxml, sed, awk,…]?

I’m using LXML library in python for XML parsing.

in a XML file, i have some bad characters that lead to below error in python:

lxml.etree.XMLSyntaxError: CharRef

Before opening and fetching the content of XML file in python, I must remove bad chars from two tags:

1: <essid cloaked="true">....</essid> or <essid cloaked="false">....</essid>.

2: <client-manuf>....</client-manuf>

the size of XML file is big. so I want to do it with sed or awk or similar tools.

    <crypt>0</crypt>
        <total>20    50</total>
        <fragments>0</fragments>
        <retries>0</retries>
    </packets>
    <datasize>0</datasize>
    <wireless-client number="1" type="established" first-time="Thu Feb 15 16:45:43 2018" last-time="Thu Feb 15 16:45:43 2018">
        <client-mac>08:EA:40:D0:55:43</client-mac>
        <client-manuf>SHENZHEN BILIAN ELECTRONIC CO.&#x  ef;&#x  bc;&#x  8c;LTD</client-manuf>
        <essid cloaked="true">&#x   0;&#x   0;&#x   0;&#x   0;&#x   0;</essid>
        <channel>8</channel>
        <maxseenrate>1.000000</maxseenrate>
        <carrier>IEEE 802.11b+</carrier>
        <encoding>CCK</encoding>
        <packets>
            <LLC>0</LLC>
            <data>0</data>
            <crypt>0</crypt>

I want to remove the bad chars from these tags (client-manuf and essid).

From: <client-manuf>SHENZHEN BILIAN ELECTRONIC CO.&#x ef;&#x bc;&#x 8c;LTD</client-manuf>

To (or this): <client-manuf>SHENZHEN BILIAN ELECTRONIC CO. LTD</client-manuf>

To (or this): <client-manuf>SHENZHEN BILIAN ELECTRONIC CO</client-manuf>

———————————————–

From: <essid cloaked="true">&#x 0;&#x 0;&#x 0;&#x 0;&#x 0;</essid>

From: <essid cloaked="false">&#x 0;&#x WiFi 0;&#x MTN 0;&#x 0;&#x 0;</essid>

To (or this): <essid cloaked="true"></essid>

To (or this): <essid cloaked="true">N/A SSID</essid>

To (or this): <essid cloaked="false">WiFi MTN</essid>

for example, two bad chars:

1: 0;

2: &#x

This is my solution. but it doesn’t work well for my needs:

sed -e '/<essid cloaked="\(true\|false"\)>*.*<\/essid>/ s/\(&#x\|0;\)//g' a.txt

Retrieving the XML data on the basis of time slots (24 slots for a day) and bind it to chart

I am trying to bind the XML data to chart but facing problem while sorting the data on the basis of time slots.

Here is the XML:

<?xml version="1.0" encoding="UTF-8"?> 
<Email> 
   <Emails> 
     <Priority>Warning</Priority>
     <DateNTime>2018-02-13 02.20.06</DateNTime>
   </Emails>
   <Emails>
     <Priority>Warning</Priority> 
     <DateNTime>2018-02-13 05.20.06</DateNTime> 
   </Emails> 
   <Emails> 
     <Priority>Information</Priority> 
     <DateNTime>2018-02-13 04.20.06</DateNTime> 
   </Emails> 
</Email>

The value of attribute “xmlns” associated with an element type “beans” must not contain the ‘<' character

Hi sir.

I am a beginner of Spiring and i am trying to develop a CRUD application using Spring MVC and Hibernate, i post my

these are the first lines of my code:

beans xmlns=”a class=”vglnk” href=”http://www.springframework.org/schema/beans” rel=”nofollow”>http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:tx=”http://www.springframework.org/schema/tx”
xmlns:mvc=”http://www.springframework.org/schema/mvc” xmlns:context=”http://www.springframework.org/schema/context”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd”>

Multiple fonts to a single custom TextView

How can we use different styles of Roboto(or any other) font (Roboto-Regular, Roboto-Thin, Roboto-Bold etc) in a single custom TextView.

One of the methods to do this programmatically is described here. But how to achieve this if we want to do change style using XML.

Can this be done using custom attributes like this?

<com.project.abc.customviews.XYZTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome"
        app:type="thin" />

I don’t want to make different java files for each type. Another method is described here but this has issues regarding memory. Looking for a good solution.

How to allow an XML element to appear anywhere via XSD?

I have the following XML:

<root>
  <someNode>
    <someChild attr="val" />
  </someNode>

  <otherNode>
    <otherChild>
      <otherSubChild />
    </otherChild>
  </otherNode>
</root>

A valid XML Schema for this will be very easy. Now the problem is, my program must support a special element which is evaluated when parsing the file, and leads to conditional substitution of elements.

Example:

    <root>
      <someNode>
        <if environment="DEV">
          <someChild attr="val" />
        </if>
        <if environment="PROD">
          <someChild attr="otherVal" />
        </if>
      </someNode>

      <otherNode>
        <otherChild>
          <if environment="DEV">
            <otherSubChild />
          </if>
        </otherChild>
      </otherNode>
    </root>

I think you get the idea. The thing is, the if element is allowed to appear everywhere in the XML, but at the same time allowed to include any element which is allowed for the element it is put in.

How would I define this in a good way? Currently I am having about 90 types/elements in my XML schema, and it would be really cumbersome to manually edit every single type/element to allow an if element which allows the correct child elements.

Is it possible to make a schema which allows the if element as I described above?