472,799 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

validating IP addresses using XML Schema

Hi,

I am looking for a way to validate IP addresses using XML Schemas. The
following is what i used:

<xsd:simpleType name="IPType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="(([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] |
25[0-5])\.){3}
([1-9]?[0-9] | 1[0-9][0-9] |
2[0-4][0-9] | 25[0-5])"/>
</xsd:restriction>
</xsd:simpleType>

I think the regular expression is correct, however an XML document with a
valid IP address doesn't pass the validation test.

Can anyone tell me what I can do to solve this?

Many Thanks
Jul 20 '05 #1
8 13423
In article <6g*****************@newsfe6-gui.ntli.net>,
UndoMiel <un*******@hotmail.com> wrote:
<xsd:pattern value="(([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] |
25[0-5])\.){3} ([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] | 25[0-5])"/>


Try removing the spaces.

-- Richard
Jul 20 '05 #2
i did, wont work...

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:ce***********@pc-news.cogsci.ed.ac.uk...
In article <6g*****************@newsfe6-gui.ntli.net>,
UndoMiel <un*******@hotmail.com> wrote:
<xsd:pattern value="(([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] | 25[0-5])\.){3} ([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] | 25[0-5])"/>


Try removing the spaces.

-- Richard

Jul 20 '05 #3

"UndoMiel" <un*******@hotmail.com> wrote in message
news:6g*****************@newsfe6-gui.ntli.net...
Hi,

I am looking for a way to validate IP addresses using XML Schemas. The
following is what i used:

<xsd:simpleType name="IPType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="(([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] |
25[0-5])\.){3}
([1-9]?[0-9] | 1[0-9][0-9] |
2[0-4][0-9] | 25[0-5])"/>
</xsd:restriction>
</xsd:simpleType>

I think the regular expression is correct, however an XML document with a
valid IP address doesn't pass the validation test.

Can anyone tell me what I can do to solve this?

Many Thanks

I used the regular expression tester at
http://www.roblocher.com/technotes/regexp.aspx

to check how well your pattern worked and it seems that for some reason the
order matters (despite what you'd think...)

this
[1-9]?[0-9]|1[0-9][0-9]

is not the same as this
1[0-9][0-9]|[1-9]?[0-9]

Anyway my tests showed that if you reorder it like this
((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0
-9][0-9]|[1-9]?[0-9])
it will work just fine.

Some regular expression expert can tell you why A|B != B|A

So try that, making sure you have no blanks to the left of the alternation
symbol '|' else it will try and match a blank there instead of the previous
digit...

HTH,
Johnny
Jul 20 '05 #4
In article <uDiQc.6675$Uh.4292@fed1read02>,
Johnny Kent <re*****************@hotmail.com> wrote:
this
[1-9]?[0-9]|1[0-9][0-9]

is not the same as this
1[0-9][0-9]|[1-9]?[0-9]


It is, according to the XML Schema specification, and other regular
expression languages I'm familiar with.

The operator | binds less tightly than any other operator, including
concatenation.

Which strings did the tester give different results for? And what browser
were you using (it tests the browser's Javascript regular expressions).

And what validator is the original poster using?

-- Richard
Jul 20 '05 #5

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:ce**********@pc-news.cogsci.ed.ac.uk...
In article <uDiQc.6675$Uh.4292@fed1read02>,
Johnny Kent <re*****************@hotmail.com> wrote:
this
[1-9]?[0-9]|1[0-9][0-9]

is not the same as this
1[0-9][0-9]|[1-9]?[0-9]
It is, according to the XML Schema specification, and other regular
expression languages I'm familiar with.


Agreed.
Sorry, instead of "(Despite what you'd think)" I should have said "contrary
to the rules of regular expressions"
in my post.


The operator | binds less tightly than any other operator, including
concatenation.

Which strings did the tester give different results for?
try entering 199 using the patterns above,
none of the 3 browsers I tried (although 2 are really mozilla though they
don't act the same) match 199
using the first pattern [1-9]?[0-9]|1[0-9][0-9]
but all 3 matched 199
using the second pattern 1[0-9][0-9]|[1-9]?[0-9]
And what browser
were you using (it tests the browser's Javascript regular expressions).


Same result for both IE5, Mozilla (1.7) and Firefox(0.8.0+)
Guess the tester must be what's bad 'cos it sure ought to work both ways.

Looks like the OP has moved on and left us to keep this alive... :-)


Jul 20 '05 #6
Hi,

I just used XMLSpy and the Topologi validator to validate the XML
document...

I've also tried another regular expression cause i couldnt get the the other
one working... Here it comes:

<xsd:restriction base="xsd:string">

<xsd:pattern
value="(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-
5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0
-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{
1 }[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])"/>

</xsd:restriction>

It's a bit longer and complicated but it worked fine....

Thanks for ur time guys...
"Johnny Kent" <re*****************@hotmail.com> wrote in message
news:ZBEQc.10034$Uh.655@fed1read02...

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:ce**********@pc-news.cogsci.ed.ac.uk...
In article <uDiQc.6675$Uh.4292@fed1read02>,
Johnny Kent <re*****************@hotmail.com> wrote:
this
[1-9]?[0-9]|1[0-9][0-9]

is not the same as this
1[0-9][0-9]|[1-9]?[0-9]
It is, according to the XML Schema specification, and other regular
expression languages I'm familiar with.


Agreed.
Sorry, instead of "(Despite what you'd think)" I should have said

"contrary to the rules of regular expressions"
in my post.


The operator | binds less tightly than any other operator, including
concatenation.

Which strings did the tester give different results for?


try entering 199 using the patterns above,
none of the 3 browsers I tried (although 2 are really mozilla though they
don't act the same) match 199
using the first pattern [1-9]?[0-9]|1[0-9][0-9]
but all 3 matched 199
using the second pattern 1[0-9][0-9]|[1-9]?[0-9]
And what browser
were you using (it tests the browser's Javascript regular expressions).


Same result for both IE5, Mozilla (1.7) and Firefox(0.8.0+)
Guess the tester must be what's bad 'cos it sure ought to work both ways.

Looks like the OP has moved on and left us to keep this alive... :-)

Jul 20 '05 #7
I just downloaded and installed an eval copy of xmlspy.
I put the following code snippets into two files, checked that they
validated with wrox.validate then loaded into xmlspy and it works and
validates just fine:

file "ip.xml"
<?xml version="1.0"?>
<IPtest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ip.xsd">
<IP>192.168.255.1</IP>
</IPtest>

file "ip.xsd"
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:simpleType name="IPType">
<xsd:restriction base="xsd:string">
<xsd:pattern
value="(([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-
9][0-9]|2[0-4][0-9]|25[0-5])"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="IPtest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="IP" type="IPType" maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I'm using XMLSPY on windows 2000 sp2, it seems to be using the xmlspy
internal validator and is working just fine.
I think you need to check either your syntax (it won't work with spaces
within the ip , or before or after and also won't work if you leave spaces
around the | in the pattern but as I have it above (like your original but
without the spaces) it validates.
HTH,
Johnny
"UndoMiel" <un*******@hotmail.com> wrote in message
news:It**************@newsfe2-gui.ntli.net...
Hi,

I just used XMLSpy and the Topologi validator to validate the XML
document...

I've also tried another regular expression cause i couldnt get the the other one working... Here it comes:

<xsd:restriction base="xsd:string">

<xsd:pattern
value="(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0- 5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0 -9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1 ]{ 1 }[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])"/>

</xsd:restriction>

It's a bit longer and complicated but it worked fine....

Thanks for ur time guys...
"Johnny Kent" <re*****************@hotmail.com> wrote in message
news:ZBEQc.10034$Uh.655@fed1read02...

"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:ce**********@pc-news.cogsci.ed.ac.uk...
In article <uDiQc.6675$Uh.4292@fed1read02>,
Johnny Kent <re*****************@hotmail.com> wrote:

>this
>[1-9]?[0-9]|1[0-9][0-9]
>
>is not the same as this
>1[0-9][0-9]|[1-9]?[0-9]

It is, according to the XML Schema specification, and other regular
expression languages I'm familiar with.


Agreed.
Sorry, instead of "(Despite what you'd think)" I should have said

"contrary
to the rules of regular expressions"
in my post.


The operator | binds less tightly than any other operator, including
concatenation.

Which strings did the tester give different results for?


try entering 199 using the patterns above,
none of the 3 browsers I tried (although 2 are really mozilla though they don't act the same) match 199
using the first pattern [1-9]?[0-9]|1[0-9][0-9]
but all 3 matched 199
using the second pattern 1[0-9][0-9]|[1-9]?[0-9]
And what browser
were you using (it tests the browser's Javascript regular
expressions).
Same result for both IE5, Mozilla (1.7) and Firefox(0.8.0+)
Guess the tester must be what's bad 'cos it sure ought to work both ways.
Looks like the OP has moved on and left us to keep this alive... :-)


Jul 20 '05 #8
"UndoMiel" <un*******@hotmail.com> writes:
Hi,

I am looking for a way to validate IP addresses using XML Schemas. The
following is what i used:

<xsd:simpleType name="IPType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="(([1-9]?[0-9] | 1[0-9][0-9] | 2[0-4][0-9] |
25[0-5])\.){3}
([1-9]?[0-9] | 1[0-9][0-9] |
2[0-4][0-9] | 25[0-5])"/>
</xsd:restriction>
</xsd:simpleType>

I think the regular expression is correct, however an XML document with a
valid IP address doesn't pass the validation test.


Note that valid IP addresses may not conform to the pattern you're
going for. Most notably, IPv6 patterns take a radically different
form.

Also, although I think almost everybody uses the 127.0.0.1 format
nowadays, traditionally you could shorten the IP address (e.g., 127.1
is the same thing as 127.0.0.1). I don't know what RFC defines that,
though, and people using IPv4 can always convert to the long form, so
that's not so important. You do need to think about the IPv6
situation, though (even if you simply decide not to handle it).
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike:o | last post by:
I need to validate XML documents (orders) against their schema before processing. The PurchaseOrder schema that we use references 3 other schemas using the <imports ...> element. Here is the...
6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
6
by: Robert Reineri | last post by:
Hello, New to the XML world and .NET. I have what I believe to be a simple problem, but I have read the .NET docs till I'm blue in the face and still can't locate a simple example of how to...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
1
by: Wallace | last post by:
Hi all, I have a problem on validating a xml fragment using a single namespace schema which spread across multiple schema files using include in the master schema file. No matter how I change...
1
by: Chris Lieb | last post by:
I have an XML Schema file that I know is correct becuase I currently use it in a VB6 program to validate XML documents. Also, if I load an XML file into VS2005 that is not valid against this...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.