vendredi 31 juillet 2015

xml with multiple data processing in django spyne

i have a server running django and spyne, i want to configure spyne to accept xml like below:

<soapenv:Envelope xmlns:soapenv="http://ift.tt/sVJIaE"
xmlns:loc="http://ift.tt/1noaANI">
<soapenv:Header/>
<soapenv:Body>

<loc:sendSms>
<loc:addresses>[addresses]</loc:addresses>
<loc:senderName>[senderName]</loc:senderName>
<loc:message>[message]</loc:message>
<loc:receiptRequest>
    <endpoint></endpoint>
    <interfaceName></interfaceName>
    <correlator></correlator>
</loc:receiptRequest>
</loc:sendSms>

<loc:sendSms>
<loc:addresses>[addresses]</loc:addresses>
<loc:senderName>[senderName]</loc:senderName>
<loc:message>[message]</loc:message>
<loc:receiptRequest>
    <endpoint></endpoint>
    <interfaceName></interfaceName>
    <correlator></correlator>
</loc:receiptRequest>
</loc:sendSms>

.
.
.

</soapenv:Body>
</soapenv:Envelope>

is it possible? how should i do so?

and changing the client is impossible, so i have to work with this format.

EDIT:

what i have done till now:

model:

class ReceiptRequestItem(ComplexModel):
    __namespace__ = 'http://ift.tt/1noaANI'
    endpoint = Unicode()
    interfaceName = Unicode()
    correlator = Unicode()

service:

class MOMessageService(ServiceBase):
    @rpc(Unicode, Unicode, Unicode, ReceiptRequestItem,
         _returns=Unicode,
         _in_variable_names={'sender_name': 'senderName',
                             'receipt_request': 'receiptRequest'},
         _operation_name='sendSms')
    def send_sms(ctx, addresses, sender_name, message, receipt_request):
         print addresses, sender_name, message, receipt_request
         return

application:

mo_message_app = Application([MOMessageService],
                             'http://ift.tt/1noaANI',
                             in_protocol=Soap11(validator='soft'),
                             out_protocol=Soap11(), )

mo_message_service = csrf_exempt(DjangoApplication(mo_message_app))

this works when there is just one

<loc:sendSms>

though there is a problem with namespaces and lxml validator will result in error.

the question is have to change the code to accept multiple tags.

P.S: also i will be grateful if someone tell me have to fix my problem with namespaces. :)

how I can create xml file in main_activity

I get String in xml format, and I need to read this information, the information is contacts. I understand how I read information on xml file in resources, but how I read information with String in xml format which not have a file? Maybe I must create xml file in main_activity, but how that do?

XML parsing in a function and return data in an array list - java [on hold]

I need to read an xml in a method and use that data to drive selenium webdriver script. I am able to read the xml data in to a Arraylist and print the contents in the console. I am also returning ArrayList in the method. I am just struggling to use that returned data in my selenium method for different browser actions(type, click etc). This is my read method which is main method of my class

public static ArrayList main(String[] args) {

    ArrayList<String> testData = null;
    try {
        testData = new ArrayList<>();

        File fXmlFile = new File("C://Javaseleniumworld/Book.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(fXmlFile);

        //optional, but recommended
        //read this - http://ift.tt/IJO9S6
        doc.getDocumentElement().normalize();

        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

        NodeList nList = doc.getElementsByTagName("staff");

        System.out.println("----------------------------");

        for (int temp = 0; temp < nList.getLength(); temp++) {

            Node nNode = nList.item(temp);

            System.out.println("\nCurrent Element :" + nNode.getNodeName());

            if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                Element eElement = (Element) nNode;

                System.out.println("firstname : " + eElement.getAttribute("id"));
                System.out.println("server : " + eElement.getElementsByTagName("firstname").item(0).getTextContent());
                String FirstName = eElement.getElementsByTagName("firstname").item(0).getTextContent();
                testData.add(FirstName);
                System.out.println("server : " + eElement.getElementsByTagName("lastname").item(0).getTextContent());
                String LastName = eElement.getElementsByTagName("lastname").item(0).getTextContent();
                testData.add(LastName);
                System.out.println("Array List" + testData);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return testData;
}

Subtractions and Divisions are giving me NaN | XSLT & XML

So, I'm trying to make a symbolic derivative calculator and it works with a single hitch. It gives me NaN with this XML

    <?xml version="1.0"?>
<sum>
    <mono>  
        <arg>3</arg>
        <var>x</var>
        <exp>2</exp>
    </mono>
</sum>

And this stylesheet that gives the numbers the behaviour they should have in a derivative.

    <xsl:stylesheet version="1.0"        xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match = "/">
    <mono>
        <arg>
            <xsl:value-of select="arg div exp"></xsl:value-of>
        </arg>
    <var>
        <xsl:if test="exp > 0"/>
        X
    </var>
    <exp>
        <xsl:value-of select="exp - 1"></xsl:value-of>
    </exp>
</mono>
</xsl:template>
</xsl:stylesheet>

Text view is not adjusting according to weights in linear layout

This is my xml file to design a layout. I am using liner layout with weights to set the layout. but text view with id data_message and its follower layout is not taking weight according to given. all other layout before it working proper. I can't understand this error. please help to find out this.

<ScrollView xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
 <LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:weightSum="100"
android:orientation="vertical"
>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="10"
    android:background="@color/primary_dark_material_dark"
    android:orientation="horizontal"
    android:weightSum="10">
    <ImageView

        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        android:src="@drawable/logoback"
        android:padding="2dp"
        android:clickable="true"
        android:id="@+id/home_img"
        />
    <TextView
        android:id="@+id/userbox"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="4.5"
        android:textColor="#ffffff">

    </TextView>
    <Spinner
        android:id="@+id/optionmenu"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="2.5"
        android:prompt="@string/profile"
        android:tag="Menu"
        android:background="#ffffff"
        ></Spinner>
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="90"
    android:background="#ffffff"
    android:layout_margin="10dp"
    android:padding="10dp"
    android:orientation="vertical"
    android:weightSum="100"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/name"
            />
        <TextView
            android:id="@+id/data_name"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
        </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

    <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/company_name"
            />
        <TextView
            android:id="@+id/data_company"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/saddress"
            />
        <TextView
            android:id="@+id/data_address"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/phone"
            />
        <TextView
            android:id="@+id/data_phnNo"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/subject"
            />
        <TextView
            android:id="@+id/data_sub"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/city"
            />
        <TextView
            android:id="@+id/data_city"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <TextView
        android:id="@+id/data_message"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:minHeight="50dp"
        android:hint="Message"
        android:background="#ffffff"
        android:padding="2dp"
        android:layout_marginBottom="5dp"
        android:textColor="@color/primary_dark_material_dark"/>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:weightSum="3">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="3">
    </LinearLayout>
    <Button
        android:id="@+id/canrplybtn"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="fill_parent"
        android:text="@string/rply"
        android:visibility="invisible"
        android:background="@color/primary_dark_material_dark"
        android:textColor="@color/abc_primary_text_material_dark"/>
</LinearLayout>
    <LinearLayout
        android:id="@+id/form"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="40"
        android:orientation="vertical"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="20dp"
        >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />
    </LinearLayout>
</LinearLayout>

Spacing (Spoofed Keyboard) Buttons Evenly Across Android LinearLayout

I have an XML layout which I'm attempting to add a series of buttons to (A-Z). Thus far I have been able to do so - however they appear lumped together on the left hand side. I'd like for them to be evenly spaced - and I thought that using something such as:

 android:layout_marginLeft="fill_parent"
 android:layout_marginRight="fill_parent"

Would space them evenly across the screen - however I'm left with multiple errors stating:

 "Error: String types not allowed (at 'layout_marginLeft' with value 'fill_parent')."

ScreenShot: http://ift.tt/1IykDdR

Current Source:

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:id="@+id/drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/drawer_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:choiceMode="singleChoice"
        android:divider="@android:color/darker_gray"
        android:dividerHeight="0.1dp"
        android:textColor="@android:color/white" />
</LinearLayout>

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

<LinearLayout
    android:id="@+id/mainContent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="00dp"
    android:layout_marginTop="0dp"
    android:orientation="vertical" >

    <!-- 1st Child Layout  (Nested In Parent Layout) with Horizontal Orientation -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginTop="15dp"
        android:background="@drawable/searchbar"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="20dip" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="380dp"
            android:layout_height="30dp"
            android:layout_alignParentTop="true"
            android:background="@drawable/searchbartxtcontainer"
            android:ems="10"
            android:hint="  Search Movies" >

            <requestFocus />
        </EditText>

        <Spinner
            android:id="@+id/spinner1"
            android:layout_marginLeft="50dp"
            android:entries="@array/home_spinner1_array"
             android:prompt="@string/select_location" 
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_toRightOf="@+id/editText1"
            android:background="@drawable/searchbartxtcontainer"
            android:textColor="@android:color/white" 
            android:hint="Rating" />

        <Spinner
            android:id="@+id/spinner2"
            android:entries="@array/home_spinner2_array"
             android:text="Genre"
            android:layout_width="140dp"
            android:layout_height="30dp"
            android:layout_alignTop="@+id/spinner1"
            android:layout_marginLeft="50dp"
            android:textColor="@android:color/white" 
            android:hint="Genre" 
            android:layout_toRightOf="@+id/spinner1"
            android:background="@drawable/searchbartxtcontainer" />

        <Button
            android:id="@+id/button1"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="33dp"
            android:textColor="@android:color/white"
            android:layout_marginLeft="50dp"
            android:background="#4D4D4D"
            android:layout_toRightOf="@+id/spinner2"
            android:text="Reset" />



        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_toRightOf="@+id/button1"
            android:layout_marginLeft="50dp"
            android:text="Sort by:"
            android:textColor="@android:color/white"  />

        <Spinner
            android:id="@+id/spinner3"
            android:layout_width="120dp"
            android:layout_height="30dp"
            android:layout_alignTop="@+id/textView1"
            android:layout_marginLeft="20dp"
            android:layout_toRightOf="@+id/textView1"
            android:background="@drawable/searchbartxtcontainer"
            android:hint="Release Date" 
            android:textColor="@android:color/white" />
    </LinearLayout>

    <!-- 2nd Child Layout  (Nested In Parent Layout) with Horizontal Orientation -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="20dip" >

        <Button
            android:id="@+id/buttona"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="A" />

        <Button
            android:id="@+id/buttonb"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="B" />

        <Button
            android:id="@+id/buttonc"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="C" />

        <Button
            android:id="@+id/buttond"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="D" />

        <Button
            android:id="@+id/buttone"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="E" />

        <Button
            android:id="@+id/buttonf"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="F" />

        <Button
            android:id="@+id/buttong"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="G" />

        <Button
            android:id="@+id/buttonh"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="H" />

        <Button
            android:id="@+id/buttoni"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="I" />

        <Button
            android:id="@+id/buttonj"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="J" />

        <Button
            android:id="@+id/buttonk"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="K" />

        <Button
            android:id="@+id/buttonl"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="L" />

        <Button
            android:id="@+id/buttonm"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="M" />

        <Button
            android:id="@+id/buttonn"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="N" />

        <Button
            android:id="@+id/buttono"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="O" />

        <Button
            android:id="@+id/buttonp"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="P" />

        <Button
            android:id="@+id/buttonq"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="Q" />

        <Button
            android:id="@+id/buttonr"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="R" />

        <Button
            android:id="@+id/buttons"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="S" />

        <Button
            android:id="@+id/buttont"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="T" />

        <Button
            android:id="@+id/buttonu"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="U" />

        <Button
            android:id="@+id/buttonv"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="V" />

        <Button
            android:id="@+id/buttonw"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="W" />

        <Button
            android:id="@+id/buttonx"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="X" />

        <Button
            android:id="@+id/buttony"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="Y" />

        <Button
            android:id="@+id/buttonz"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_marginLeft="fill_parent"
            android:layout_marginRight="fill_parent"
            android:layout_toRightOf="@+id/spinner2"
            android:text="Z" />
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/imageView1" >

        <!-- 3rd Child Layout  (Nested In Parent Layout) with Horizontal Orientation -->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="0dp"
            android:background="#000000"
            android:orientation="vertical" >

            <!-- Container view to scroll horizontally which gives the carousel effect -->

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" />
            </HorizontalScrollView>

            <!-- Container view to scroll horizontally which gives the carousel effect -->

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal" />
            </HorizontalScrollView>

            <!-- Container view to scroll horizontally which gives the carousel effect -->

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal" />
            </HorizontalScrollView>

            <!-- Container view to scroll horizontally which gives the carousel effect -->

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal" />
            </HorizontalScrollView>

            <!-- Container view to scroll horizontally which gives the carousel effect -->

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal" />
            </HorizontalScrollView>

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal" />
            </HorizontalScrollView>

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none" >

                <!-- Carousel items container - lays out items horizontally -->

                <LinearLayout
                    android:id="@+id/carousel7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:orientation="horizontal" />
            </HorizontalScrollView>
        </LinearLayout>
    </ScrollView>
    <!-- 4th Child Layout  (Nested In Parent Layout) with Horizontal Orientation -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/clear" />
    </LinearLayout>
</LinearLayout>

<ProgressBar
    android:id="@+id/progress_bar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:indeterminateDrawable="@drawable/ic_launcher"
    android:visibility="gone" >
</ProgressBar>
<!-- List of Actions (pages) -->

<ListView
    android:id="@+id/navList"
    android:layout_width="280dp"
    android:layout_height="match_parent"
    android:layout_below="@+id/profileBox"
    android:layout_gravity="end"
    android:background="#ffffffff"
    android:choiceMode="singleChoice" />

<ImageView
    android:id="@+id/drawer_item_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

XML Parsing to .txt file Python

I need to parse this XML Document and move the date and time into a %Y-%m-%d %H:%M:%S format as well as the variables hourly-qpf and probability-of-precipitation to columns in a tab-delimited .txt file.

All I have managed to do is read in the XML file using this code:

page = urllib2.urlopen('http://ift.tt/1SP09yO')
page_content = page.read()
with open('KBFI.xml', 'w') as fid:
    fid.write(page_content)

I am at a loss after this. I've only parsed one XML doc before, and it looked completely different from this.

EDIT

Sorry for not having anything to give you guys before, but I wasn't sure what module to use, as I only have experience with minidom and it didn't seem like the right choice. I've been messing around with Element Tree and I have come up with this:

data = []
import xml.etree.ElementTree as ET
tree = ET.parse('KBFI.xml')
root = tree.getroot()
for data in root.findall('data'):
    for time-layout in root.findall('time-layout'):
        start-valid-time = time-layout.find('start-valid-time')
        time = datetime.datetime.strptime(start-valid-time, '%Y-%m-%dT%H:%M:%S')
    for parameters in root.findall('parameters'):
        for probability-of-precipitation in root.findall('probability-of-precipitation'):
            value = probability-of-precipitation.find('value')
    for hourly-qpf in root.findall('hourly-qpf'):
            value2 = hourly-qpf.find('value')
data = data.append([time,
                    value,
                    value2])
with open('KBFI.txt','w') as file:
    file.writelines('\t'.join(map(str,i)) + '\n' for i in data)

However, there is a problem because the variables are hyphenated and I do not know how to change them to underscores or remove them. Also, because of this, I have no idea if my code is any good!

Got NullPointerException when applying DOM Technique in XML Parser

I ran this program and it reported NullPointerException at this line

NodeList nodeList = root.getChildNodes();

Here is the whole thing:

package com.example.dom_technique;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class DOM extends Activity {

private Button button;
private TextView textView;

protected void onCreate(Bundle x) {
    super.onCreate(x);
    setContentView(R.layout.activity_dom);

    button = (Button) findViewById(R.id.button1);
    textView = (TextView) findViewById(R.id.textView1);

    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                readXML();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    });
}

private void readXML() throws ParserConfigurationException, SAXException, IOException {
    String output = "";

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    InputStream inputStream = getResources().openRawResource(R.drawable.student);
    Document doc = builder.parse(inputStream);

    Element root = doc.getDocumentElement();
    NodeList nodeList = root.getChildNodes();

    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);

        if (node instanceof Element) {
            Element student = (Element) node;
            String name = student.getAttribute("name");
            String student_id = student.getAttribute("student_id");

            NodeList subNodeList = student.getElementsByTagName("school");  
            String school = subNodeList.item(0).getTextContent();

            subNodeList = student.getElementsByTagName("major");
            String major = subNodeList.item(0).getTextContent();

            output += name + "  " + student_id + "\n" + school + "\n" + major +"\n" + "     ***********" + "\n";
        }
    }
    textView.setText(output);
}

}

And XML file I wrote by myself:

<?xml version="1.0" encoding="utf-8"?><students>

<student name="Henry Thompson" student_id="63827614">

    <school>University of California, Berkeley</school>
    <major>Computer Science</major>

</student>

<student name="Sheila Lopez" student_id="02817281">

    <school>University of California, Los Angeles</school>
    <major>Electrical Engineering</major>

</student>

<student name="Gabriel Carter" student_id="92717290">

    <school>University of California, Davis</school>
    <major>Mathematics</major>

</student>

<student name="Stephanie Nguyen" student_id="83729337">

    <school>University of California, San Diego</school>
    <major>Business Administraion, Concentration in Marketing</major>

</student>

Barely can I understand why, I thought I went through every requirements. I suspect the problem may come from the XML file. At first, I tried to create a XML file in drawable folder and it reported bug. Therefore I wrote in notepad, saved with xml extension and imported into drawable, then it was fine. Please help me!!! Thank you so much!!!!!!

Associate captions with images

I have two images in my xml:

<imageGroup>
    <image xlink:href="mums528-i001-001.png"/>
    <caption>page 1</caption>
</imageGroup>
<imageGroup>
    <image xlink:href="mums528-i001-002.png"/>
    <caption>page 2</caption>
</imageGroup>

I want my xsl to put each caption with its associated image, rather than having the images appear together, then the captions. This is my xsl:

<xsl:if test="//imageGroup">
        <xsl:for-each select="//image/@xlink:href">
            <img>
                <xsl:attribute name="src">
                    <xsl:value-of select="."/>
                </xsl:attribute>
            </img>
        </xsl:for-each>
        <xsl:for-each select="//caption">
            <p><xsl:value-of select="."/></p>
        </xsl:for-each>
    </xsl:if>

How can I put the images and the captions inside the same xsl for-each statement?

How do I remove the root element of an XML document?

I want to remove the root element from an following xml using Java:

<BookRequest xsi:schemaLocation="http://test/books.xsd">
 <Book>
 <Name>abc</Name>
 <Author>xyz</Author>
 </Book>
</BookRequest>

so that I will only have this as the final output:

<Book>
 <Name>abc</Name>
 <Author>xyz</Author>
</Book>

How can I do this?

Import data into Google Sheets using IMPORTXML with the div-class

I did some research and found a div-class example of importXML for Google Sheets (see first sample code below), however it doesn't appear to be working in this instance with a BBC website in Arabic. Does anyone have insight on how to solve this?

=IMPORTXML("http://www.w3.org/","//div[@class='event closed expand_block']//text()"))

=IMPORTXML("http://ift.tt/1KFfkJ6","//div[@class='top-stories__stories']//text()")

Bonus points if anyone can figure how to group the data from individual news stories using JOIN.

Build errors with XML to java object converter dependency in build.gradle for retrofit

I am trying to integrate XML to Java object converter into retrofit by following this http://ift.tt/1DWS1FL

I am getting build errors when I added dependency to my build.gradle.

This is what I've added in my build.gradle. compile ('com.squareup.retrofit:converter-simplexml:1.9.0')

Error Report:

Information:Gradle tasks [:app:assembleDebug]
Warning:Dependency xpp3:xpp3:1.1.3.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency xpp3:xpp3:1.1.3.3 is ignored for release as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages


SO I TRIED this

compile ('com.squareup.retrofit:converter-simplexml:1.9.0') {
exclude group: 'xpp3', module: 'xpp3'
}

Error report with this:

trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
....
...
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

I tried gradle clean, build clean everything but of no use. Help me if you've any idea on it.

Sort AndroidManifest File

I am trying to sort a large android manifest file. Is there a standard way of doing this? I have looked into xslt but have yet to find a stylesheet that will do what I need.

A sample might be something like this, where I would want the output to be sorted by the name of the object recursively and then by android:name param on the object if it exists:

<?xml version="1.0" encoding="utf-8"?>

<manifest>

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration />  
    <uses-feature />  
    <supports-screens />  
    <compatible-screens />  
    <supports-gl-texture />  

    <application>

        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>

Android: Draw a picture frame around any size image

Im basically trying to do this in xml http://ift.tt/1MCBHly

Anyone know how do it?

Why is javax.xml.xpath parsing my xml wrong?

After parsing the following xml,

<html>
    <body>
        <a>
            <div>
                <span>foo</span>
            </div>
        </a>
    </body>
</html>

the javax.xml.xpath Document parser indicates the following:

  • div is the parent node of a
  • a is the parent node of of span

Why is this, and how can I properly parse this xml?

Here is the code I am using, followed by it's output.

String myxml = ""
    + "<html>"
    + "<body>"
    + "<a>"
    + "<div>"
    + "<span>foo</span>"
    + "</div>"
    + "</a>"
    + "</body>"
    + "</html>";

Document doc = HttpDownloadUtilities.getWebpageDocument_fromSource(myxml);

XPath xPath = XPathFactory.newInstance().newXPath();

Node node = ((Node)xPath.compile("//*[text() = 'foo']").evaluate(doc, XPathConstants.NODE));

System.out.println("       node tag: " + node.getNodeName());
System.out.println("     parent tag: " + node.getParentNode().getNodeName());
System.out.println("grandparent tag: " + node.getParentNode().getParentNode().getNodeName());

Set<Node> nodes = H.getSet((NodeList)xPath.compile("//*").evaluate(doc, XPathConstants.NODESET));

for (Node n : nodes) {
    System.out.println();
    try {
        System.out.println("node: " + n.getNodeName());
    } catch (Exception e) {
    }
    try {
        System.out.println("child: " + n.getChildNodes().item(0).getNodeName());
    } catch (Exception e) {
    }
}

output:

       node tag: span
     parent tag: a
grandparent tag: div

node: html
child: head

node: head

node: body
child: html

node: html
child: body

node: body
child: a

node: a

node: div
child: a

node: a
child: span

node: span
child: #text

apply powershell script to multiple xml files

I have a Powershell script that queries an xml document and outputs the results to a csv file. The script works but I need to apply it to multiple xml files in a folder and output the combined results to a csv. How can this script be modified to do this? Thanks

$xml = [XML](Get-Content D:demo\test.xml) #load xml document

#this finds file names of yearbook picks
$picks = $xml.Client.Order.Ordered_Items.Ordered_Item |
    Where-Object { $_.Description -eq 'yearbook Luster Print' } |
        ForEach-Object { $_.Images.Image_Name }


# this finds the Album
$album = $xml.SelectSingleNode("//Album_ID").InnerText -split '_'

$results = New-Object PSObject -Property @{
      Last= $album[0]
      First= $album[1]
      Code= $album[2]
      Pick1= $picks[0]
      Pick2= $picks[1]
    }

#output CSV File
$results | Export-Csv -path D:\demo\myoutput.csv -NoTypeInformation

Add Action Rule Axis Camera

I am trying to use the vapix API for Axis cameras to make a new action rule. The responses for this API are hilariously unhelpful. My error is : "The requested SOAP action failed" . I am using SOAPUI 5.2.0. Here is my code:

<soap:Envelope xmlns:soap="http://ift.tt/18hkEkn" xmlns:SOAP-ENC="http://ift.tt/1cvL1jU" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" xmlns:c14n="http://ift.tt/11kTCUR" xmlns:wsu="http://ift.tt/Hm2joJ" xmlns:ds="http://ift.tt/uq6naF" xmlns:wsse="http://ift.tt/LRW8Ij" xmlns:wsa5="http://ift.tt/HKXHai" xmlns:xmime="http://ift.tt/1LP4jbf" xmlns:xop="http://ift.tt/1euX8oV" xmlns:wsrfbf="http://ift.tt/1cvL1Ai" xmlns:wstop="http://ift.tt/1cvL3s5" xmlns:tt="http://ift.tt/1cvL1Ag" xmlns:acert="http://ift.tt/1DWHUkg" xmlns:wsrfr="http://ift.tt/1leiF5D" xmlns:aa="http://ift.tt/1LP4jbj" xmlns:acertificates="http://ift.tt/1IzbYrz" xmlns:aev="http://ift.tt/1LP4iUP" xmlns:ali1="http://ift.tt/1LP4jrz" xmlns:ali2="http://ift.tt/1MSjz49" xmlns:ali3="http://ift.tt/1LP4jrB" xmlns:ali4="http://ift.tt/1LP4lQh" xmlns:ali="http://ift.tt/1LP4lQk" xmlns:apc="http://ift.tt/1DWHWsr" xmlns:arth="http://ift.tt/1IzbWA7" xmlns:aweb="http://ift.tt/1DWHUAE" xmlns:tan1="http://ift.tt/1MSjz4d" xmlns:tan2="http://ift.tt/1LP4jrG" xmlns:tan="http://ift.tt/1leiDe2" xmlns:tds="http://ift.tt/1leiEPp" xmlns:tev1="http://ift.tt/1cvL1Au" xmlns:tev2="http://ift.tt/1cvL3Ix" xmlns:tev3="http://ift.tt/1leiF5N" xmlns:wsnt="http://ift.tt/1leiEPh" xmlns:tev4="http://ift.tt/1leiDuF" xmlns:tev="http://ift.tt/1cvL3Ik" xmlns:timg="http://ift.tt/1sSAh9q" xmlns:tptz="http://ift.tt/1cvL3Is" xmlns:trt="http://ift.tt/1cvL0wr" xmlns:ter="http://ift.tt/1leiEyG" xmlns:tns1="http://ift.tt/1cvL3rY" xmlns:tnsaxis="http://ift.tt/1MSjxcw">
  <soap:Header/>
  <soap:Body>
    <act:AddActionRule>
    <act:NewActionRule>
      <!--Optional:-->
      <act:Name>AHHHHH</act:Name>
      <act:Enabled>true</act:Enabled>
      <!--Optional:-->
      <!--<act:StartEvent>-->
      <!--You may enter ANY elements at this point-->
      <!--</act:StartEvent>-->
      <!--Optional:-->
      <act:Conditions>
        <!--1 or more repetitions:-->
        <act:Condition>
          <wsnt:TopicExpression Dialect="http://ift.tt/1IzbWQp">tns1:Device/ tnsaxis:IO/Port//.</wsnt:TopicExpression>
          <wsnt:MessageContent Dialect="http://ift.tt/1DWHWIR">boolean(//SimpleItem[@Name="state" and @Value="1"]) and boolean(//SimpleItem[@Name="port" and @Value="0"])</wsnt:MessageContent>
        </act:Condition>
      </act:Conditions>
      <!--Optional:-->
      <!--act:ActivationTimeout>?</act:ActivationTimeout-->
      <act:PrimaryAction>16</act:PrimaryAction>
      <!--Optional:-->
      <!--act:FailoverAction>?</act:FailoverAction-->
    </act:NewActionRule>
  </act:AddActionRule>
</soap:Body>

To be honest I am not sure what the things inside the condition are doing. I went into the camera setup and added the action rule through the setup, then used another soap command "GetActionRules" to see how to format it. The GeActionRules command is

<soap:Envelope xmlns:soap="http://ift.tt/18hkEkn" xmlns:act="http://ift.tt/1LP4jbj">
   <soap:Header/>
   <soap:Body>
      <act:GetActionRules/>
   </soap:Body>
</soap:Envelope>

And the response is

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://ift.tt/18hkEkn" xmlns:SOAP-ENC="http://ift.tt/1cvL1jU" xmlns:xsi="http://ift.tt/ra1lAU" xmlns:xsd="http://ift.tt/tphNwY" xmlns:c14n="http://ift.tt/11kTCUR" xmlns:wsu="http://ift.tt/Hm2joJ" xmlns:ds="http://ift.tt/uq6naF" xmlns:wsse="http://ift.tt/LRW8Ij" xmlns:wsa5="http://ift.tt/HKXHai" xmlns:xmime="http://ift.tt/1LP4jbf" xmlns:xop="http://ift.tt/1euX8oV" xmlns:wsrfbf="http://ift.tt/1cvL1Ai" xmlns:wstop="http://ift.tt/1cvL3s5" xmlns:tt="http://ift.tt/1cvL1Ag" xmlns:acert="http://ift.tt/1DWHUkg" xmlns:wsrfr="http://ift.tt/1leiF5D" xmlns:aa="http://ift.tt/1LP4jbj" xmlns:acertificates="http://ift.tt/1IzbYrz" xmlns:aev="http://ift.tt/1LP4iUP" xmlns:ali1="http://ift.tt/1LP4jrz" xmlns:ali2="http://ift.tt/1MSjz49" xmlns:ali3="http://ift.tt/1LP4jrB" xmlns:ali4="http://ift.tt/1LP4lQh" xmlns:ali="http://ift.tt/1LP4lQk" xmlns:apc="http://ift.tt/1DWHWsr" xmlns:arth="http://ift.tt/1IzbWA7" xmlns:aweb="http://ift.tt/1DWHUAE" xmlns:tan1="http://ift.tt/1MSjz4d" xmlns:tan2="http://ift.tt/1LP4jrG" xmlns:tan="http://ift.tt/1leiDe2" xmlns:tds="http://ift.tt/1leiEPp" xmlns:tev1="http://ift.tt/1cvL1Au" xmlns:tev2="http://ift.tt/1cvL3Ix" xmlns:tev3="http://ift.tt/1leiF5N" xmlns:wsnt="http://ift.tt/1leiEPh" xmlns:tev4="http://ift.tt/1leiDuF" xmlns:tev="http://ift.tt/1cvL3Ik" xmlns:timg="http://ift.tt/1sSAh9q" xmlns:tptz="http://ift.tt/1cvL3Is" xmlns:trt="http://ift.tt/1cvL0wr" xmlns:ter="http://ift.tt/1leiEyG" xmlns:tns1="http://ift.tt/1cvL3rY" xmlns:tnsaxis="http://ift.tt/1MSjxcw">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <aa:GetActionRulesResponse>
         <aa:ActionRules>
            <aa:ActionRule>
               <aa:RuleID>8</aa:RuleID>
               <aa:Name>FTP</aa:Name>
               <aa:Enabled>true</aa:Enabled>
               <aa:Conditions>
                  <aa:Condition>
                     <wsnt:TopicExpression Dialect="http://ift.tt/1IzbWQp">tns1:Device/tnsaxis:IO/Port//.</wsnt:TopicExpression>
                     <wsnt:MessageContent Dialect="http://ift.tt/1DWHWIR">boolean(//SimpleItem[@Name="port" and @Value="0"]) and boolean(//SimpleItem[@Name="state" and @Value="1"])</wsnt:MessageContent>
                  </aa:Condition>
               </aa:Conditions>
               <aa:PrimaryAction>13</aa:PrimaryAction>
           </aa:ActionRule>
            <aa:ActionRule>
               <aa:RuleID>9</aa:RuleID>
               <aa:Name>noobbbb</aa:Name>
               <aa:Enabled>true</aa:Enabled>
               <aa:Conditions>
                  <aa:Condition>
                     <wsnt:TopicExpression Dialect="http://ift.tt/1IzbWQp">tns1:Device/tnsaxis:IO/Port//.</wsnt:TopicExpression>
                     <wsnt:MessageContent Dialect="http://ift.tt/1DWHWIR">boolean(//SimpleItem[@Name="port" and @Value="0"]) and boolean(//SimpleItem[@Name="state" and @Value="1"])</wsnt:MessageContent>
                  </aa:Condition>
               </aa:Conditions>
               <aa:PrimaryAction>14</aa:PrimaryAction>
            </aa:ActionRule>
         </aa:ActionRules>
      </aa:GetActionRulesResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How do I select from xml document multiple times with powershell

I am trying to select multiple groups of elements from an XML document, the sample below shows the type of structure I'm using. Why does the powershell code below only output the 2 names, but not the 2 stores.

[xml]$xml = @'
<root>
  <node>
    <store>HEB</store>
    <name>Fred</name>
  </node>
  <node>
    <store>Fred Meyer</store>
    <name>Barney</name>
  </node>
</root>
'@;

$xml.root.node | select  name -unique

$xml.message.node | select store -unique

Output

.\test.ps1

name
----
Fred
Barney

Unable to add Schemas (xsd) in XML setting

I am trying to add the xsd file (schema) for the XML in IntelliJ but when I select any file, the add button gets disabled.

For adding schema, I followed following path:

File -> Settings -> Languages & Frameworks -> Schemas and DTDs - (+) button under 'External Schemas and DTDs' section

Please find the attached image below.

enter image description here

Thanks in advance for the help :)

XSD: Substitutiongroup when there may be multiple elements for that group in xml

Is it possible to make substitutiongroups work if I am uncertain whether or not one or both elements will be present in the xml?

For instance we could get this xml:

<topnode>
    <subnode1/>
    <subnode2/>
</topnode>

or this:

<topnode>
    <subnode1/>
</topnode>

The following xsd will work for the second XML we received, but not the first.

<xs:element name="topnode">
    <xs:complexType>
        <xs:all>
            <xs:element ref="subnodes">
        </xs:all>
    </xs:complexType>
</xs:element>
<xs:element name="subnodes" abstract="true"/>
<xs:element name="subnode1" substitutiongroup="subnodes"/>
<xs:element name="subnode2" substitutiongroup="subnodes"/>

I know that could already take care of this behavior, however I am trying to get "or" type behavior that can be chained.

I appreciate any help!

can not reading from database in my code

I am new to android application development and I have written the following code to start a google map applicaton which reads some data from an sqlite databse. I considered reading database from a path as it has big data, but I encountered the error "Failed to open database '/data/data/http://ift.tt/1Iz6jlq'" in logcat.

Could you please help me finding the problem?

MainActivity.java

package com.mymap.www;
import java.text.DecimalFormat;
import java.util.List;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.app.Dialog;
import android.database.DataSetObserver;
import android.database.SQLException;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

private MapView mapView;
DatabaseHelper dataBase;
Typeface typeface;

private GoogleMap googleMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
        // Loading map
        initilizeMap();
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Changing map type
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    // Showing / hiding your current location
    googleMap.setMyLocationEnabled(true);

    // Enable / Disable zooming controls
     googleMap.getUiSettings().setZoomControlsEnabled(true);

     // Enable / Disable my location button
     googleMap.getUiSettings().setMyLocationButtonEnabled(true);

     // Enable / Disable Compass icon
     googleMap.getUiSettings().setCompassEnabled(true);

     // Enable / Disable Rotate gesture
     googleMap.getUiSettings().setRotateGesturesEnabled(true);

     // Enable / Disable zooming functionality
     googleMap.getUiSettings().setZoomGesturesEnabled(true);

 // Setting a click event handler for the map
    googleMap.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng latLng) {

            // Creating a marker
            MarkerOptions markerOptions = new MarkerOptions();

            // Setting the position for the marker
            markerOptions.position(latLng);

            googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

                // Use default InfoWindow frame
                @Override
                public View getInfoWindow(Marker arg0) {             
                    return null;
                }

                // Defines the contents of the InfoWindow
                @Override
                public View getInfoContents(Marker arg0) {

                    // Getting view from the layout file info_window_layout
                    View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

                    // Getting the position from the marker
                    LatLng latLng = arg0.getPosition();

                    // Getting reference to the TextView to set latitude
                    TextView tvLat = (TextView) v.findViewById(R.id.tv_lat);

                    // Getting reference to the TextView to set longitude
                    TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);

                    double lat;
                    double lng;

                    lat =Double.parseDouble(new DecimalFormat("##.########").format(latLng.latitude));
                    lng =Double.parseDouble(new DecimalFormat("##.########").format(latLng.longitude));

                    dataBase = DatabaseHelper.instance(lat,lng);

                    // Setting the latitude
                    tvLat.setText("Latitude:" + lat);

                    // Setting the longitude
                    tvLng.setText("Longitude:"+ lng);


                    // Returning the view containing InfoWindow contents
                    return v;
                }
            });
            // Clears the previously touched position
            googleMap.clear();

            // Animating to the touched position
            googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));

            // Placing a marker on the touched position
            googleMap.addMarker(markerOptions);

        }
    });    

     double latitude = 17.385044;
    double longitude = 78.486671;

}

private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        // check if map is created successfully or not
        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

ApplicationContentProvider.java

package com.mymap.www;

import android.app.Application;
import android.content.Context;
public class ApplicationContextProvider extends Application {
    /**
     * Keeps a reference of the application context
     */
    private static Context sContext;
    @Override
    public void onCreate() {
        super.onCreate();
        sContext = getApplicationContext();
    }
    /**
     * Returns the application context
     *
     * @return application context
     */

    public static Context getContext() {
        return sContext;
    }
}

DatabaseHelper.java

package com.mymap.www;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.TextView;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class DatabaseHelper extends SQLiteOpenHelper {
    SQLiteDatabase mDataBase;
    static double latitude;
    static double longitude;
    int count;
    // The Android's default system path of your application database.
    //data/data/ and /databases remain the same always. The one that must be changed is com.example which represents
    //the MAIN package of your project
    private static String DB_PATH = "/data/data/http://ift.tt/1Ud2FS8";

    //the name of your database
    private static String DB_NAME = "database.db";
    private static final String SQLITE_TABLE = "data91";
    private static final String TAG = "ConcentrationDbAdapter";
    private static DatabaseHelper sInstance = null;
    // database version
    private static final int DATABASE_VERSION = 1;

    /**
     * Constructor Takes and keeps a reference of the passed context in order to
     * access to the application assets and resources.
     */
    private DatabaseHelper() { 
        super(ApplicationContextProvider.getContext(), DB_PATH + DB_NAME, null, DATABASE_VERSION);
        try{
            createDataBase();
        }
        catch (IOException e){
            throw new Error("Error copying database");
        } 
        try {
            createDataBase();
            openDataBase();
        } catch (IOException e) {
        e.printStackTrace();
    }

}
/**
 * Singleton for DataBase
 *
 * @return singleton instance
 */
public static DatabaseHelper instance(double lat, double lng) {
    latitude = lat;
    longitude = lng;

    if (sInstance == null) {
        sInstance = new DatabaseHelper();
    }

    return sInstance;
}
/**
 * Creates a empty database on the system and rewrites it with your own
 * database.
 *
 * @throws java.io.IOException io exception
 */
private void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
        // do nothing - database already exist
    } else {
        // By calling this method an empty database will be created into
        // the default system path
        // of your application so we are gonna be able to overwrite that
        // database with our database.
        this.getReadableDatabase();
        try {
            copyDataBase();
        } catch (IOException e) {
            throw new Error("Error copying database");
        }
    }
}
/**
 * Check if the database already exist to avoid re-copying the file each
 * time you open the application.
 *
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        // database doesn't exist yet.
        throw new Error("database doesn't exist yet");
    }
    if (checkDB != null) {
        checkDB.close();
    }
    return checkDB != null;
}
/**
 * Copies your database from your local assets-folder to the just created
 * empty database in the system folder, from where it can be accessed and
 * handled. This is done by transfering bytestream.
 *
 * @throws java.io.IOException io exception
 */
public void copyDataBase() throws IOException {
    // Open your local db as the input stream
    InputStream myInput = ApplicationContextProvider.getContext().getAssets().open(DB_NAME);
    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;
    // Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);
    // transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    // Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();
}
private void openDataBase() throws SQLException {
    // Open the database
    String myPath = DB_PATH + DB_NAME;
    mDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
}
/**
 * Select method
 *
 * @param query select query
 * @return - Cursor with the results
 * @throws android.database.SQLException sql exception
 */
public Cursor select(String query) throws SQLException {
    return mDataBase.rawQuery(query, null);
}
/**
 * Insert method
 *
 * @param table  - name of the table
 * @param values values to insert
 * @throws android.database.SQLException sql exception
 */
public void insert(String table, ContentValues values) throws SQLException {
    mDataBase.insert(table, null, values);
}
/**
 * Delete method
 *
 * @param table - table name
 * @param where WHERE clause, if pass null, all the rows will be deleted
 * @throws android.database.SQLException sql exception
 */
public void delete(String table, String where) throws SQLException {
    mDataBase.delete(table, where, null);
}
/**
 * Update method
 *
 * @param table  - table name
 * @param values - values to update
 * @param where  - WHERE clause, if pass null, all rows will be updated
 */
public void update(String table, ContentValues values, String where) {
    mDataBase.update(table, values, where, null);
}
/**
 * Let you make a raw query
 *
 * @param command - the sql comand you want to run
 */
public void sqlCommand(String command) {
    mDataBase.execSQL(command);
}
@Override
public synchronized void close() {
    if (mDataBase != null)
        mDataBase.close();
    super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

info_window_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv_lat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_lng"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_co"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_no2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_no"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_nox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_o3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_pm10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_pm2_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_so2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_aqi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.airpollutionmap.www"
android:versionCode="1"
android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
    <uses-permission
        android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission
        android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission
        android:name="com.mymap.http://ift.tt/1Iz6jls" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyC1BF_BwuWL_iiXx6VCXF6zDFEJk9_U33g"/>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
                    android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

How to use toprettyxml() to give xml tag and text in same line

I have this text file 20150731100543_1.txt

GI-eSTB-MIB-NPH::eSTBGeneralErrorCode.0 = INTEGER: 0
GI-eSTB-MIB-NPH::eSTBGeneralConnectedState.0 = INTEGER: true(1)
GI-eSTB-MIB-NPH::eSTBGeneralPlatformID.0 = INTEGER: 2075
GI-eSTB-MIB-NPH::eSTBMoCAfrequency.0 = INTEGER: 0
GI-eSTB-MIB-NPH::eSTBMoCAMACAddress.0 = STRING: 0:0:0:0:0:0
GI-eSTB-MIB-NPH::eSTBMoCANumberOfNodes.0 = INTEGER: 0

Which I want to convert in xml like below (20150731100543_1.xml)

<?xml version="1.0" encoding="UTF-8"?>
<doc>
    <GI-eSTB-MIB-NPH>
        <eSTBGeneralErrorCode.0>
            INTEGER: 0
        </eSTBGeneralErrorCode.0>
    </GI-eSTB-MIB-NPH>
    <GI-eSTB-MIB-NPH>
        <eSTBGeneralConnectedState.0>
            INTEGER: true(1)
        </eSTBGeneralConnectedState.0>
    </GI-eSTB-MIB-NPH>
    <GI-eSTB-MIB-NPH>
        <eSTBGeneralPlatformID.0>
            INTEGER: 2075
        </eSTBGeneralPlatformID.0>
    </GI-eSTB-MIB-NPH>
    <GI-eSTB-MIB-NPH>
        <eSTBMoCAfrequency.0>
            INTEGER: 0
        </eSTBMoCAfrequency.0>
    </GI-eSTB-MIB-NPH>
    <GI-eSTB-MIB-NPH>
        <eSTBMoCAMACAddress.0>
            STRING: 0:0:0:0:0:0
        </eSTBMoCAMACAddress.0>
    </GI-eSTB-MIB-NPH>
    <GI-eSTB-MIB-NPH>
        <eSTBMoCANumberOfNodes.0>
            INTEGER: 0
        </eSTBMoCANumberOfNodes.0>
    </GI-eSTB-MIB-NPH>
</doc>

I am able get this done using following script:

import sys
import time
import commands
from xml.etree.ElementTree import Element, SubElement
from xml.etree import ElementTree
from xml.dom import minidom

def prettify(elem):
    """Return a pretty-printed XML string for the Element.
    """
    rough_string = ElementTree.tostring(elem, 'utf-8')
    reparsed = minidom.parseString(rough_string)
    return reparsed.toprettyxml(indent="    ", newl="\n", encoding="UTF-8")

if len(sys.argv) != 2:
    print "\nUsage: python script.py <IP>\n";
    exit(0)
filename_xml = '20150731100543_1.xml'#filename_xml = temp + ".xml"
print "xml filename is: %s\n" % filename_xml
xml = open(filename_xml, 'w+')

top = Element('doc')

with open('20150731100543_1.txt') as f:
    for line in f:
        b = line.split(':')
        child = SubElement(top, b[0])

        c = line.split()
        d = c[0].split(':')
        property =  SubElement(child, d[2])

        property.text = c[2] + " " + c[3]

xml.write(prettify(top))

xml.close()

I have three questions here:

  1. Is there any way (using toprettyxml() or something else) I can change the xml that is being generated to have openeing and closing tags and text in that tag in same line?
  2. Also can I have tag only at starting an at the end instead of having it with every element below it? (as all the elements are within this same tag)

So if possible the format of xml should be like:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
    <GI-eSTB-MIB-NPH>
        <eSTBGeneralErrorCode.0>INTEGER: 0</eSTBGeneralErrorCode.0>
        <eSTBGeneralConnectedState.0>INTEGER: true(1)</eSTBGeneralConnectedState.0>
        <eSTBGeneralPlatformID.0>INTEGER: 2075</eSTBGeneralPlatformID.0>
        <eSTBMoCAfrequency.0>INTEGER: 0</eSTBMoCAfrequency.0>
        <eSTBMoCAMACAddress.0>STRING: 0:0:0:0:0:0</eSTBMoCAMACAddress.0>
        <eSTBMoCANumberOfNodes.0>INTEGER: 0</eSTBMoCANumberOfNodes.0>
    </GI-eSTB-MIB-NPH>
</doc>

I am trying for this as this will reduce the number of lines in xml to great extent.

The last and least important question is:

  1. Is there any better way to get the substrings of each line than how I have done it using split()

    with open('20150731100543_1.txt') as f: for line in f: b = line.split(':') child = SubElement(top, b[0])

        c = line.split()
        d = c[0].split(':')
        property =  SubElement(child, d[2])
    
        property.text = c[2] + " " + c[3]
    
    

Please forgive me for such lengthy post.

deserialize xml into inherited classes from base class

I have the following xml structure:

<Root1>
    <name>Name1</name>
    <company>Comp1</company>
    <url>site.com</url>
    <elements>
        <element id="12" type="1">
            <url>site1.com</url>
            <price>15000</price>
            ...
            <manufacturer_warranty>true</manufacturer_warranty>
            <country_of_origin>Япония</country_of_origin>
        </element>
        <element id="13" type="2">
            <url>site2.com</url>
            <price>100</price>
            ...
            <language>lg</language>
            <binding>123</binding>
        </element>
    </elements>
</Root1>

I need deserialize this xml structure to object. How you can see the element contains some equals field: url and price. I would like to move these fields into a separate class and then inherit this class by other classes.

I created the class Root1:

namespace app1
{
    [Serializable]
    public class Root1
    {
        [XmlElement("name")] 
        public string Name { get; set; }

        [XmlElement("company")] 
        public string Company { get; set; }

        [XmlElement("url")] 
        public string Url { get; set; }

        [XmlElement("elements")]
        public List<Element> ElementList { get; set; }
    }
}

and then I created base class for Element:

[Serializable]
    public class Element
    {
        [XmlElement("url")] 
        public string Url { get; set; }

        [XmlElement("price")] 
        public string Price { get; set; }
    }

and then I inherited this class by other classes:

[Serializable]
public class Element1 : Element
{
    [XmlElement("manufacturer_warranty")] 
    public string mw { get; set; }

    [XmlElement("country_of_origin")] 
    public string co { get; set; }
}

[Serializable]
public class Element2 : Element
{
    [XmlElement("language")] 
    public string lg { get; set; }

    [XmlElement("binding")] 
    public string bind { get; set; }
}

When I deserializing this xml to object Root1 I get the object - it is ok. But the List of Elements contains only Element objects not Element1 and Element2 objects.

How I do deserialize this xml that list of Elements contains Element1 and Element2 objects?

JavaScript setTimeout loop only running twice before returning error:

I've been working on a website that processes XML files, And I ran into an issue once I added a bit more processing. The issue I am having is in using setTimeout to give the browser a break to 'breathe' so that it doesn't crash trying to load a bunch of information into innerHTML. When I load it, it only loops twice, then returns an error of "VM###:1"(### constantly changes).

var i = 0;
    var run = process();
    process();
    function process(){
        if (i < x.length) {
            var name = $(x[i]).find("Description[DescriptionCode='DEF']").text();
            var ixx = x.length + (20 - (x.length % 20));
            var ix = Math.round((i+10) / 20);
            var type = "";
            var desc = $(x[i]).find("Description[DescriptionCode='DES']").text();
            var lamp = desc;
            var g = 1;
            var id = $(x[i]).find("PartNumber").text();
            var ddId = "D" + id + "D"
            var price = $(x[i]).find("Pricing[PriceType='RMP']").find("Price").text();
            for (n=0;(g == 1) && (n < sType.length); n++) {
                if (desc.indexOf(sType[n].type) > -1) {
                    type = sType[n].type;
                    lamp = lamp.replace(sType[n].type, '');
                    g = 0;
                }
            };
            for (n=0;(g == 1) && (n < sVolume.length); n++) {
                if (desc.indexOf(sVolume[n].vol) > -1) {
                    vol = sVolume[n].vol;
                    lamp = lamp.replace(sVolume[n].vol, ''); 
                    g = 0;
                }
            };
            for (n=0;(g == 1) && (n < sYear.length); n++) {
                if (desc.indexOf(sYear[n].year) > -1) {
                    year = sYear[n].year;
                    lamp = lamp.replace(sYear[n].year, '');
                    g = 0;
                }
            };

            document.getElementById("productDiv").innerHTML += "The stuff I'm processing goes here.";
            i++;
        setTimeout("process", 1);
        }
    };

Scraping data using Xpath in curl in R

I am trying to scrape the movie list. For some reason i am getting no values in the movies vector. I am trying to the movies releases this week. Any suggestions?

library(curl)
library(XML)

movies<- xpathSApply(htmlTreeParse("http://www.imdb.com", useInternalNodes = TRUE, encoding='UTF-8'), "//div[2]/div[5]/span/div[1]/div/div/div", xmlValue)
movies<- data.frame(movies)

Double Encoding of HTML Entities in XML using VB.NET

I am trying to create an XML file using VB.NET for a system that accepts XML information for publication on their website. Even though special characters like © & ® are acceptable in the XML, they really should be encoded to &copy; and &reg;.

The problem that I am having is when I insert &copy; into the XML, it results in a double-encoding of &amp;copy; in the XML, if I insert ©, then © is inserted unencoded.

I created a bare-bones example that I have replicated the problem with below, it has the same XML structure as what I need. I'm using HtmlAgilityPack to convert entities.

Imports HtmlAgilityPack

Private Sub webXML()

    Dim oXml As New XmlDocument

    oXml.LoadXml("<webTable xmlns=""http://ift.tt/1Jk9NWv"" xmlns:n1=""http://ift.tt/1IP9A1K"" xmlns:xsi=""http://ift.tt/1fQ42a7"" xsi:schemaLocation=""http://ift.tt/1IP9A1L""></webTable>")

    ''Add Namespace
    Dim NS As New Xml.XmlNamespaceManager(oXml.NameTable)
    NS.AddNamespace("ns", "http://ift.tt/1Jk9NWv")
    NS.AddNamespace("n1", "http://ift.tt/1IP9A1K")
    NS.AddNamespace("xsi", "http://ift.tt/1fQ42a7")

    ''Create XML declaration 
    Dim xmldecl As XmlDeclaration
    xmldecl = oXml.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
    xmldecl.Encoding = "UTF-8"

    ''Add node to document 
    Dim root As XmlElement = oXml.DocumentElement
    oXml.InsertBefore(xmldecl, root)

    ''info
    Dim info As XmlNode = oXml.CreateNode("element", "info", "http://ift.tt/1Jk9NWv")

    ''data1
    Dim data1 As XmlNode = oXml.CreateNode("element", "data1", "http://ift.tt/1Jk9NWv")
    Dim data1Value As String = HtmlEntity.Entitize(Trim("Company Name 1 ©"), True)
    Dim data1Text As XmlText = oXml.CreateTextNode(data1Value)
    data1.AppendChild(data1Text)
    info.AppendChild(data1)
    Console.WriteLine("Data1 value: " + data1Value)
    Console.WriteLine("Data1 text node value: " + data1Text.Value)
    Console.WriteLine("Data1 node text value: " + data1.InnerText)
    Console.WriteLine("Data1 node XML value: " + data1.InnerXml)

    ''data2
    Dim data2 As XmlNode = oXml.CreateNode("element", "data2", "http://ift.tt/1Jk9NWv")
    Dim data2Value As String = Trim(HtmlEntity.Entitize("Company Name 2 ®", False))
    data2.InnerText = data2Value
    info.AppendChild(data2)
    Console.WriteLine("Data2 value: " + data2Value)
    Console.WriteLine("Data2 node text value: " + data2.InnerText)
    Console.WriteLine("Data2 node XML value: " + data2.InnerXml)

    ''data3
    Dim data3 As XmlNode = oXml.CreateNode("element", "data3", "http://ift.tt/1Jk9NWv")
    Dim data3value As String = Trim(HtmlEntity.Entitize("Company Name 3 ®", False))
    data3.InnerXml = data3value
    info.AppendChild(data3)
    Console.WriteLine("Data3 value: " + data3value)
    Console.WriteLine("Data3 node text value: " + data3.InnerText)
    Console.WriteLine("Data3 node XML value: " + data3.InnerXml)

    ''Add info to Root
    root.AppendChild(info)

    oXml.Save(Console.Out)
    oXml.Save("C:\Users\Chris\Dropbox\SECUREX\Junk\textXML.xml")

End Sub

The output I get is:

Data1 value: Company Name 1 &copy;
Data1 text node value: Company Name 1 &copy;
Data1 node text value: Company Name 1 &copy;
Data1 node XML value: Company Name 1 &amp;copy;
Data2 value: Company Name 2 &#174;
Data2 node text value: Company Name 2 &#174;
Data2 node XML value: Company Name 2 &amp;#174;
Data3 value: Company Name 3 &#174;
Data3 node text value: Company Name 3 ®
Data3 node XML value: Company Name 3 ®
<?xml version="1.0" encoding="Windows-1252"?>
<webTable xmlns="http://ift.tt/1Jk9NWv" xmlns:n1="http://ift.tt/1IP9A1K" xmlns:xsi="http://ift.tt/1fQ42a7" xsi:schemaLocation="http://ift.tt/1IP9A1L">
  <info>
    <data1>Company Name 1 &amp;copy;</data1>
    <data2>Company Name 2 &amp;#174;</data2>
    <data3>Company Name 3 ®</data3>
  </info>
</webTable>

As you can see I have tries several different ways and I still can't get the entities encoded right.

Please note that oXml.Save(Console.Out) shows Windows-1252 encoding but my output file is identical except it shows it properly as UTF-8.

I'm using VS 2012 Express.

Any idea what I can do to encode the HTML entities properly?

Thanks in advance.