UDP development-DTD validation, DOM parsing

Source: Internet
Author: User

Bloggers are too lazy to provide a sample program

6, based on UDP Development

(1) Sender:socket-> preparing the packet

Datagramsocket docket = new Datagramsocket ();

Prepare the packet,

InetAddress ia = inetaddress.getbyname (" IP address of each other ");

Datagrampacket DP = new Datagrampacket (Str.getbytes (), full length of bytes , address , port number );

Send Data

Socket.send (DP);

(2) Receiving party:

Datagramsocket socket= New Datagramsocket ( port number );

preparing to receive packets

Byte[] B = new byte[1024];

Datagrampacket DP = new Datagrampacket (b,b.lenth);

Receive Data

Socket.receiver (DP);

to save data from a byte array to a string

string s = new string (Dp.getdata (), 0,dp.getdata (). length);

Add: After you establish this link, you can return data without specifying a port

SocketAddress sa = dp.getsocketaddress ();

byte[] by = Str.getbytes ();

Datagrampacket data = new Datagrampacket (BY,BY.LENGTH,SA);

7. JUnit Add

Right- Click items :"Build path"->configure build path->libararies->add library->junit- >next, down

Pull menu Select JUint4->finish->ok

1.XML declaration statement:<?xml version= "1,0" encoding= "UTF-8"?>

Well-formed XML documents need to meet:

<1> must have an XML declaration

<2> must have and have only one root element

<3> label Case Sensitive

<4> double quotes for attribute values

<5> Label pairs

<6> elements are properly nested

2. DTD Validation:

(1) Function: to limit the format of XML file, ensure the file format is normalized

(2) Realization:

<! DOCTYPE root Tag name [

<! Element tag name (content included in the label)>// between the three are separated by a space

]>

Limit the number of occurrences of a label symbol:

? --0-1 Times

+--1 to multiple times

*--0 to multiple times

(3) Verify attributes:

<! The Attlist property sits in the Tag Property Name property value type [ other ]>

Property type:cdata- biausse text

Other:#REQUIRED-- required

3. External DTD

Introduce syntax:

<! DOCTYPE root element SYSTEM "DTD file " >

Note: The element and attlist tags are used directly in the DTD file

In general, an external DTDis introduced.

File suffix dtd.

Using the DOM to parse the objects used primarily by XML

4. Objects used:Document,NodeList,Node,Element

Document represents The properties of the XML decoupling unit

NodeList represents the label pair collection

Node represents a pair of tags with extreme content

Element represents a label for obtaining a property

(2) Common methods

Document :

Getdocuementelement ():element- get root element

getElementsByTagName (" label "): Gets the specified list of tags

NodeList:

Item (int index): iterates through each node

Element :getattribute (" attribute name "): Returns the value of a property in a tag

Node:

Getnodename ():// Get node name

Gettextcontent ():// Gets the text in the label pair

Note: When you get the property value of a tag, you need to strongly convert the Node object to Element

Before the strong turn, first judge:

If (Node.getnodetype () ==element.element_node) {

Element e = (element) node;

String attribute = E.getattriubute (" attribute name ");

}

UDP development-DTD validation, DOM parsing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.