Solved

dtd and xml not jiving

Posted on 2011-03-03
5
326 Views
Last Modified: 2012-05-11
So I have an xml feed that I am getting from another system and so I created a dtd as part of the mapping process on my end.  However right now they dont like each other.  I have been starring at this for a while and I need to see if someone can point out the error of my ways.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ItemInquiry SYSTEM "ItemInquiry.dtd" > 
<ItemInquiry> 
<Code="7VQ"  Item="ST4006"  Dollars="228.00"  Error="S" /> 
<Code="XXX"  Item="6444.54"  Dollars="44.95"  Error="X" /> 
<Code="QFY"  Item"ST2753D"  Dollars="228.00"  Error=" " /> 
<Code="WTF"  Item="ST4006"  Dollars="168.00"  Error=" " /> 
</ItemInquiry> 


<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ItemInquiry ( Code | Item | Dollars | Error )* >
<!ELEMENT Code ( #PCDATA ) >
<!ELEMENT Item ( #PCDATA ) >
<!ELEMENT Dollars ( #PCDATA ) >
<!ELEMENT Error ( #PCDATA ) >

Open in new window

0
Comment
Question by:iceman19330
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35026940
well, your XML is not wellformed,
you seem to have only attributes and no element name
You could rather mean something like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ItemInquiry SYSTEM "ItemInquiry.dtd" > 
<ItemInquiry>
<Item Code="7VQ"  Name="ST4006"  Dollars="228.00"  Error="S" />
<Item Code="XXX"  Name="6444.54"  Dollars="44.95"  Error="X" />
<Item Code="QFY"  Name"ST2753D"  Dollars="228.00"  Error=" " />
<Item Code="WTF"  Name="ST4006"  Dollars="168.00"  Error=" " />
</ItemInquiry>


0
 

Author Comment

by:iceman19330
ID: 35026964
what would the dtd look like?

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ItemInquiry ( Code | Name | Dollars | Error )* >
<!ELEMENT Code ( #PCDATA ) >
<!ELEMENT Name ( #PCDATA ) >
<!ELEMENT Dollars ( #PCDATA ) >
<!ELEMENT Error ( #PCDATA ) >
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 35026969
Having this as XML

<ItemInquiry>
    <Item Code="7VQ"  Name="ST4006"  Dollars="228.00"  Error="S" />
    <Item Code="XXX"  Name="6444.54"  Dollars="44.95"  Error="X" />
    <Item Code="QFY"  Name="ST2753D"  Dollars="228.00"   />
    <Item Code="WTF"  Name="ST4006"  Dollars="168.00"   />
</ItemInquiry>

This would be the DTD
<!ELEMENT ItemInquiry ( Item )* >
<!ELEMENT Item EMPTY  >
<!ATTLIST Item 
    Code CDATA #REQUIRED 
    Name CDATA #REQUIRED 
    Dollars CDATA #REQUIRED 
    Error (S | X ) #IMPLIED >

Open in new window

0
 

Author Comment

by:iceman19330
ID: 35027098
Thank you for the promptness and throughness of your answer.

Now with the Error do I just need to list the possible flags that come back in the DTD and if there is no flag then its blank but I dont need to do anything with that blank spot in the DTD?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35027463
Ah, the blank spot, You can't express the blank spot in a finite list
I made the attribute implied, so you can leave it out as an alternative to a blank spot
If you can't leave the attribute out as an alternative, you need to make it CDATA as the rest

   Error CDATA  #REQUIRED >
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now